- In homework assignment 3, you created a shell script MyFriends,
which listed all the processes your friends were running.
For this problem, you will create an advanced version of MyFriends -
MyFriendsV2. It accepts arguments, which are either your friends' login
names (login IDs) or files which contain lists of login IDs (one per
line). If an argument is a file name, you can assume it is a file
containing a list of login IDs (one per line). If it is not a file
name, you can assume it is a login name.
For this part, you should submit a well commented listing (WCL) of
MyFriendsV2 and at least 2 sample runs showing how (well) it works.
Include also (of course) an explanation of the sample runs, stating how they
show that your MyFriendsV2 works well.
- Create a sh shell script called AllProcesses,
which creates a report file about current processes running on the
system you are using. The report should include how many process are
running, how many unique commands are running, how many distinct
terminals are being used for these processes. After giving these
statistics the report should list each user's login ID following by all
the processes belonging to this ID. The report sections for different
users should be separated from each other by a blank line.
For this part, submit the same type of WCL and sample runs with
explanations as you did for the previous part.
- This part continues the work you did in the previous part. After
you obtained report from AllProcesses, you want to receive, via
e-mail, a report of the processes belonging to a particular person (a
friend or even yourself). Create another shell script called
FriendProc which takes 3 arguments: an e-mail address, a login
ID, and the "real name" of the person to whom the login ID belongs. It
extracts from from the report produced by AllProcesses all information
relevant to the login ID (the third argument). It then prepares a
suitable e-mail message, including the person's "real name" and login ID
in the first lines, and sends it to the e-mail address given by the
first argument. Your solution may well create some intermediate
file(s). If so, they should be named in such a way that you could run
more than one copy of the program at the same time and they should be
deleted when the program exits. You need not actually send the
e-mail. It is sufficient that you echo to the screen a line giving the
command that would e-mail the message to the given address.
For this part, submit the same type of WCL and sample runs with
explanations as you did for the previous parts.
- In this part, give both the awk command and a sample of its use.
- Write any line in which the second field contains a backslash.
- Write (only) the last two fields in each line, separated by a colon.
- Write the line number and number of fields in each line separated by
a colon.
- Write lines longer than 66 characters.
- In this part, you will create several small (sh) shell
scripts for the following requirements. You need to submit listings of
your scripts and explanations about how they work including, as
appropriate, suitably edited sample runs.
- Read in two numbers from the keyboard and print their sum.
- Write a shell script that given a person's uid, tells you how many
times that person is logged on.
- Write a shell script taking a filename name as argument which lists
the files in it (using ls -l piped to more) if it's a
directory and shows the content of the file (using more) if it
is a regular file.
- In many versions of UNIX there is a -i argument for
cp so that you will be prompted for confirmation if you are
about to overwrite a file. Write a script called cpi which
will prompt if necessary.