Main Course Webpage

CS160A Assignment 3

Objective: Write your first shell script to output information about the current user and the current system in a readable format understandable to the novice. This will require the use of echo to output messages as well as the use of shell commands to generate the data. This assignment must be done on hills.

Description

This shell script, aboutme, must output the following information about whoever runs it ('you' below). Most of the information is extracted from commands. Some is contained in standard shell variables:

  1. A welcome message indicating your real name as identified in the passwd file or output as the In Real Life name by pinky -l)

  2. How many classes you are taking this semester.

  3. The host you are logged in on, how long the host has been up, how many users are logged in, and what its 1-minute load average is.

  4. The directories in your search path, in the order they are searched, one-per-line

  5. Your terminal type (the value of the variable that indicates your terminal type).

  6. How much disk space your home directory is consuming (in kiB), and how many files and how many directories your home directory has beneath it (Hint: use find)

The output must be readable, and each piece of information must be identified with a text message. Do your best to output complete sentences and control line breaks.

If you create temporary files during your shell script's run, you must delete them when it is finished. Temporary files should not be necessary and you must at least limit their use.

A script session asmt03.script containing sample output of Greg Boyd's version of this shell script may be found in the asmt03 directory. This is just one version. Take the time to design your own output!

Here are a few more hints:

Turning in Your Assignment

Upload a copy of your script aboutme and a script session which shows you running your script aboutme to Canvas.

Read the sample output closely before you write and test your shell script

You can do this entire assignment using simple commands, pipes and echo. To make your script look cleaner, you can use command-subsitution. Command-substitution can be used to place the output of a command in a variable. You can then use the variable's value in the middle of an echo statement. For example:

nusers=Command-substitution of the command to extract the number of users from uptime

echo "There are $nusers logged in."

Do not place the command-substitution directly in the echo command as that is difficult to read. You can try to use the newer $( ) form of command-substitution rather than the old ` ` form. We will cover more of this in CS160B.