M01:
Introduction to Operating Systems |
TU3:
Installing specific purpose software |
ASIX1 |
Pract. Exerc. 3: Introduction to shell scripts | 28-03-22 |
1- Write a
script to create a new group in your system. Your script will
terminate returning an exit code exit code equal to 0 if
everything works fine but, if your script fails to create the
new group, it will terminate returning an exit code equal to 1.
Save your script with the following name: newgroup.sh. Run and check
if your script works.
2- Write a script to create a new user in your
system. Your script will terminate returning an exit code equal
to 0 if everything works fine but, if your script fails
to create the new user, it will terminate returning an exit code
equal to 1. Save your script with the following name: newuser.sh. Run and check if
your script works.
3- Write a script called loginteller.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 terminate returning an exit code equal to 1 and
showing: "This script must be run as root".
b) Secondly, it tries to download loginteller.tar.gz
which is a file stored in a software repository whose URL
is http://www.collados.org/asix1/m01/tu3/loginteller.tar.gz.
if your script fails to download loginteller.tar.gz, it
will terminate returning an exit code equal to 2 and
showing: "File not found".
c) Thirdly, the
contents of loginteller.tar.gz will be extracted. After
extracting its contents, two new files should have been created:
loginteller.c and Makefile.
d) Fourthly, loginteller.c will
be compiled running the command make loginteller
and a new binary program called loginteller will be
created on our system. If loginteller.c is not
succesfully compiled, your scripts will display "File not
compiled" and it will be terminated returning an exit code equal
to 3.
e) Fifthly, loginteller
will be installed on your system running make install.
If loginteller is not succesfully installed, your
script will display "Progran was not installed" and it
will be terminated returning an exit code equal to 4.
f) Finally, your script will
run make clean to clean any temporary file created when
loginteller.c was compilled. If your script does
not work properly, the following message wil be displayed:
"Problems cleaning temporary files", and it will be
terminated returning an exit code equal to 5.
g) Your script must terminate
returning an exit code equal to 0 if everything works
fine.
4- Write 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 terminate
returning an exit code equal to 1 and showing: "This
script must be run as root".
b) Secondly, it tries to
download bomba.deb
which is a file stored in a software repository whose URL
is 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:
"Debian package not found".
c) Thirdly, bomba.deb will be
installed on your system with the help of dpkg.
If bomba.deb is not succesfully installed on your
system, your script will display "Debian package not
installed on your system" and it will be terminated returning an
exit code equal to 3.
d) Finally, the newly installed program called bomba
will be run. 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.
e) Your script must terminate
returning an exit code equal to 0 if everything works
fine.
5- Write a script called rmbomb.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 terminate
returning an exit code equal to 1 and showing: "This
script must be run as root".
c) Secondly, 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 not uninstalled
and purged" and it will be terminated returning an exit code
equal to 2.
c) Your script must
terminate returning an exit code equal to 0 if
everything works fine.
6- Write a script called mltpusr.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 terminate
returning an exit code equal to 1 and showing: "This
script must be run as root".
b) Secondly, it tries to
download users.ods which is a file stored in
a software repository whose URL is http://www.collados.org/asix1/m01/tu3/users.ods.
if your script fails to download users.ods, it will
terminate returning an exit code equal to 2 and showing:
"Users list not found".
c) Thirdly, users.ods
will be saved as new text .csv file called users.csv
. If users.ods can not be saved as users.csv,
your script will display "Conversion failure" and it will
be terminated returning an exit code equal to 3.
d) Finally, your script will create a new user on yur
system for each username written in users.csv. For each
new user, the default group will be users, the default
shell will be /bin/bash and the default password will be
fjeclot. Your script will ask for an initial UID that
will be assigned to the first user. The UID value will be
increased before creating a new user. If your script can not
create a user, the following message will be displayed:
"Problems creating a user", and it will be terminated returning
an exit code equal to 4.
e) Your script must terminate
returning an exit code equal to 0 if everything works
fine.
7- Write a script called dmltpusr.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 terminate
returning an exit code equal to 1 and showing: "This
script must be run as root".
b) Secondly, it tries to
download users.ods which is a file stored in
a software repository whose URL is http://www.collados.org/asix1/m01/tu3/users.ods.
if your script fails to download users.ods, it will
terminate returning an exit code equal to 2 and showing:
"Users list not found".
c) Thirdly, users.ods
will be saved as new text .csv file called users.csv
. If users.ods can not be saved as users.csv,
your script will display "Conversion failure" and it will
be terminated returning an exit code equal to 3.
d) Finally, your script will remove any user (and its
personal folder) that appears in users.csv. If
your script can not remove a user, the following message will be
displayed: "Problems removing a user", and it will be terminated
returning an exit code equal to 4.
e) Your script must terminate
returning an exit code equal to 0 if everything works
fine.
8- Write a script called menu.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) Run a command to update the list of
software packages available
2) Run a command to install a package
called alpine-pico
3) Run a command to to install a package
called vim
4) Run a command to remove alpine-pico
5) Run a command to remove vim
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.
9- Write a script called
perm.sh with the following features:
ASIX1 - List of students
and scripts
DAW1
- List of students and scripts