CS 1206: Assignment 6

Due Friday, August 6, 1999 by 5pm

100 Points


Writing A Shell Script

There are two parts to this assignment. Both parts should work correctly to get full credit.
 
  1. In part 1 of your assignment, you are supposed to write a simple shell script called whereami. When invoked, this script  prints out the user name of the current user, the name of the current machine, the full path name of the current working directory,  the current time, and a listing of the contents of the current directory. Output from your whereami script should follow this example.

    % whereami
    You are         : mfali

  2. You are on      : csgrad.cs.vt.edu
    Current directory : /home/mfali
    Time is         : Tue Aug  3 01:19:29 EDT 1999
    Current directory contents:
    A5.ps               bin/                mail/               public_html/
    C++/                c*                  main.cpp            research/
    MCCNRR99.xls        courses/            mfali.gz            scores.htm
    Mail/               cs1206.xls          mfali.txt           scripts-i.ps
    Makefile            cvsroot/            names.txt           scripts-ii.ps
    News/               d@                  ns_imap/            squid-1.1.22/
    PGP/                getopt.c            nsmail/             squid-2.2.STABLE2/
    a*                  grades.htm          oldsquid.gz         temp/
    a.c                 hw3-3.doc           oldsquid2.gz
    active-cache.ps     index.html          print/
    b*                  java/               priv/
     
  3. Here, you are supposed to write a shell script called listdir. that takes one command line argument. This is assumed to be a valid directory pathname. Your script when invoked, lists the contents of that directory. It also displays the number of ordinary files, executable files, directories, and links in that directory. If no pathname is specified on the command line, then the script works on the current working directory. Sample output from your listdir command follows:

  4. % listdir /home/mfali
    Contents of directory are:
    A5.ps               bin/                mail/               public_html/
    C++/                c*                  main.cpp            research/
    MCCNRR99.xls        courses/            mfali.gz            scores.htm
    Mail/               cs1206.xls          mfali.txt           scripts-i.ps
    Makefile            cvsroot/            names.txt           scripts-ii.ps
    News/               d@                  ns_imap/            squid-1.1.22/
    PGP/                getopt.c            nsmail/             squid-2.2.STABLE2/
    a*                  grades.htm          oldsquid.gz         temp/
    a.c                 hw3-3.doc           oldsquid2.gz
    active-cache.ps     index.html          print/
    b*                  java/               priv/

    19 ordinary, 3 executable, 18 directories, 1 links.
     

Remember that your shell scripts must start with a proper "bang line":
    #!/bin/ksh
They should also end with a proper return statement. Your shell scripts will be graded on a DEC Alpha running Digital UNIX, so you should write your scripts such that it runs correctly under both FreeBSD and Digital UNIX. You can test your scripts on any of the DEC Alphas (doberman, malamute, rottweiler, boxer, husky) in the lab.

Sources For Information

Your shell scripts are free to access any shell or environment variables, and call any commands provided on the system. Some shell variables you might wish to explore include: Some commands that may also be of use are (see their respective manual pages):

Part III: Submitting Your Answers

You are to submit your assignment via email to the class account at cs1206@ei.cs.vt.edu.  Your subject line should  read "HW 6".  Attach your script files to your message as two separate files, and not as one file. Do not include them in the body of your message. You should immediately get an acknowledgement back. It is important that you follow these steps exactly.

Also, remember that no late assignments are accepted.