MS-373
Advanced Unix
Lab 8
Date: Thursday, February 2, 2006
Due: Thursday, February 16, 2006
Writing Real Shell Scripts
One of the reasons for learning to write shell scripts is to be able to
author new commands that perform some useful systems administration tasks.
So after consulting with our own Unix/Linux systems administrators, here are several ideas for useful shell scripts. The assignment
is to write an appropriate shell script to
address the stated problems below. Be sure to describe in your report the
details of the design, implementation and testing of your solution.
- Write a script to detect if/when a specific username logs on to a
system. The script would contact someone, in some way, when the given
username is detected to be logged on. It would have to have a way to only
contact once per the given username's login session (off the top of my head, i
might use the w, who, or last command to help accomplish the contact-once
idea). Such a process could be run as a daemon (i.e. using an infinite
loop) or via a cron job that only checks every couple of minutes.
- Write a script to send an 'SMS' message to a cell phone. Obviously, don't
attempt this task unless you have a cell phone. Most cell phone services
provide a way for a 'text' (which really means SMS) message to be sent to the
phone via some website or email address. Write a script to do this, so that
it can be done programatically. If via email, you might want to use any 1 of
these email clients: mutt, pine, elm, Mail, mailx, sendmail. If via the
web, you might want to use any 1 of these web clients: GET, wget, curl, or
even telnet.
- Write a script to give the 'family tree' of some process (i.e. to show
all the ancestors all the way back up to the mother-of-all processes, init (pid
1)). I know there are several ways to show the descendants of a given pid,
but i don't know of tool to show the ancestors.
If your script gets involved, you may want to add options to it, just as the
other shell commands allow. The options are typically single letter
options following the dash (i.e. ls -l uses the l
option to mean long listing). To process command options, use the built-in
bash function getopts() or the shell equivalent getopt.