IT 244: Introduction to Linux/Unix
Homework 11
Due Monday, May 7th 11:59 PM
All this work should be done on users3.cs.umb.edu
Deliverables
-
A shell script named parameters.sh
30 points
-
A shell script named log_users.sh
40 points
-
A shell script named envir.sh
30 points
Create an hw11 directory in your hw
directory inside your it244 directory.
Using the Unix editor of your choice, create the scripts
in your hw11 directory.
Remember to create a hashbang line at the top and to include
a comment describing what the script does.
Be sure to make this file executable in the manner
I described in class.
If the script must have some number of arguments, make sure you test for the proper number of arguments.
If the script does not get the correct number of arguments, it should print a usage message and quit.
If you do not have a hashbang line, do not have a comment
describing what the script does, do not make it properly
executable, or fail to check for arguments and provide a usage message, points will be deducted.
Details
parameters.sh
The script should do the following:
-
Print the the positional parameters 0 through 4 to the terminal.
-
Print the number of arguments given to this script from the command line.
Each positional parameter must be labeled and printed on a separate line.
Be sure to test this script several times to make sure it works.
Your output should look something like this
$ ./parameters.sh foo bar bletch bling
$0 ./parameters.sh
$1 foo
$2 bar
$3 bletch
$4 bling
$# 4
log_users.sh
The script should do the following:
- Define a variable log whose value
is the filename for the log file, users.log .
-
Append the date to the log file whose name is contained in log.
-
Append a line of dashes to this log file to act as a separator.
-
Append a list of the users currently on to users3 to this log file.
-
Append a blank line to the log file.
The value users.log should be assigned to the variable at the top of the script.
Thereafter, never never write "users.log" in your script.
Use the value of log instead.
Be sure you append the output so the log grows each time you run the script.
After running this script twice, the log file users.log should look something like this:
$ cat users.log
Wed Dec 5 10:38:58 EST 2012
-----------------
Login Name Tty Idle Login Time Office Office Phone
it244gh Dummy for Glenn Hoffman pts/0 Dec 5 10:29 (dsl092-066-161.bos1.dsl.speakeasy.net)
Wed Dec 5 10:39:06 EST 2012
-----------------
Login Name Tty Idle Login Time Office Office Phone
it244gh Dummy for Glenn Hoffman pts/0 Dec 5 10:29 (dsl092-066-161.bos1.dsl.speakeasy.net)
Be sure to test this script several times to make sure it works.
envir.sh
The script should do the following:
- Test that it has been given a command line argument.
It should print a usage message and exit if no argument is given.
- List all global variables that contain the string given in
the command line argument.
Do this using a pipe calling env
and then grep
to
filter the output of env
for variables which
contain the string given as an argument to the script.
Thus, if I wanted to see all variables that contained "SSH", I would run
./envir.sh SSH
Be sure to test this script several times to make sure it works.