M01:
Introduction to Operating Systems |
TU3:
Installing specific purpose software |
ASIX1 |
Pract. Exerc. 3: Introduction to shell scripts | 21-03-23 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2- Develope a script
called backup.sh that:
a) Firstly, it checks if
the script is being run by the root user. If it is not
being run by the root user, it will be
terminated returning an exit code equal to 1 and
showing: "This script must be run as root".
b) Afterwards, check if a directory called /backups
exists on your system. If the directory does not exist, it
will be created. If the directory can not be created, your
script will be terminated
returning an exit code equal to 2 and showing:
"/backups can not be created".
c) Ask the user for a directory name inside /backups.
If the directory does not exist, it will be created by your
script. If the directory can not be created, your script will be
terminated returning an exit code equal to 3 and
showing: "Error creating directories in /backups"".
d)
Ask the user an extension
e) Ask the user a directory name where files with
the extension given by the user could be found.
f) Each file in the second directory will be copied in
the directory created in step c).
g) Finally, the script packs and compress the directory created in step c)
adding to file name the current date and time.
Your script will
terminate returning an exit code exit code equal to 0
if everything works
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3- Develope a
script called bomb.sh
that:
a) Firstly, it checks if
the script is being run by the root user.
If it is not being run by the root
user, it will be terminated returning an exit code equal
to 1 and showing: "This script must be run as
root".
b) Secondly, it shows a menu with the following
options:
1) Download bomba.deb from http://www.collados.org/asix1/m01/tu3/bomba.deb. if your script fails
to download bomba.deb, it will terminate returning
an exit code equal to 2 and showing: "Package not
found".
2)
Intall bomba.deb on
your system with the help of dpkg.
If bomba.deb is not succesfully installed on your
system, your script will display "Debian package can
not be installed on your system" and it will be terminated
returning an exit code equal to 3.
3) Run bomba. If your script can not run bomba,
the following message wil be displayed: "Problems running
bomba", and it will be terminated returning an exit
code equal to 4.
4) Uninstall and purge bomba.deb with
the help of dpkg.
If bomba.deb is not succesfully uninstalled and
purged, your script will display "Debian package can
not beuninstalled and purged" and it will be terminated
returning an exit code equal to 5.
If you select any other option, the following message will
be displayed: "Wrong option. Please, select 1/2/3/4/".
c) Thirdly, your
script asks the user if he/she wants to display again
the menu in order to select a new option. If the
user writes "yes" the menu is shown again.
Otherwise, the script ends.
d) Your script must terminate returning an exit
code equal to 0 if everything works fine.
4- Write a script
called menu_installer.sh
that:
a) Firstly, it checks if the
script is being run by the root user. If it is not
being run by the root user, it will be terminated
returning an exit code equal to 5 and showing: "This
script must be run as root".
b) Secondly, it shows a menu with the following options:
1) Run a command to update the list of
software packages available
2) Run a command to install a package
called ipcalc
3) Run a command to to install a package
called jed
4) Run a command to remove ipcalc
5) Run a command to remove and purge jed
If you select any other
option, the following message will be displayed: "Wrong option.
Please, select 1/2/3/4/5"
c) Thirdly, the selected option is run.
d) Finally, it shows a message asking the user if he/she
wants to continue (option y) or not (option n). If
the user select y, the terminal will be cleared and the
menu will be shown again.
e) Your script must terminate
returning an exit code equal to 0 if everything works
fine.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PRACTICAL EXERCISES -
SOLUTIONS --> here