BD350 HW 3

Linux 01 - Shell Scripting

Due: 2006 Oct 6, beginning of class

Name: _________________________________

Score:  _____ / 52 = _____ / 100

Linux Shell Scripting

 

This assignment is to be done on your class Linux server.  Make sure all output is formatted nicely and neatly.    I will be grading all your assignments by logging in with my account and invoking my root (administrator) status.  Thus, there is not anything you need to submit to me in order for me to grade your assignment.  You simply do the work in your account on the machine, and I will grade it there.  Be sure to complete your work before the start of class on the due date.  Any files updated after the start of class on the due date will not be given credit.  (Only work available for me to grade on this machine in your assigned account will be given credit.)  NOTE: You will probably need to understand how to use “cut”, “head”, “tail”, and "echo" (and possibly other commands) for a number of these problems.  Read the man pages for additional info.

 

You should use basic bash shell scripting, and NOT rely on or use awk, perl, etc.  Use commands we have discussed in class and that are in the class slides.  If you have an interest in using other tools, get approval from the teacher beforehand.

                                   

1.   (2 pts) Log in to your account on your Linux server and change your password.  Be sure to follow good password selection conventions.

2.      (2 pts) Create a subdirectory tree called “BD350/HW03” within your home directory on the Linux server.  (Note that this is all uppercase, and note the zero in the "HW03" subdirectory name.)  Perform the remaining parts of this assignment in that directory.  Make sure that your scripts are well documented and clean up after themselves, i.e. delete any temporary files.  Make sure that the only files in this directory are the scripts and output data files required below.

3.   (6 pts)  For each of the following, give the Linux command or pipelined command sequence (not the output) that would perform the requested task.  Note that you are to provide the command that you used to answer the question, not the output of the command.

a.    Display a count of the number of files (including directories) in a long directory listing (with the ls command, use only the -l option)

b.    Display only the file / directory names from a long directory listing (with the ls command, use only the -l option)

c.    Store the size of the largest file from a file / directory listing (ls) into a variable called SIZE (2 pts extra credit if you use no ls options other than -l)

Each command should be able to be run as one command-line execution.  In other words, do not issue multiple commands on multiple lines to accomplish any one of these tasks.  Issue a single-line command or set of pipelined commands.  Put the answers (the commands / command sequences) to these three questions in a file called 03-commands.txt.

4.   (5 pts) Get a list of processes the root user is currently running. Use the ps command to see these. Run the ps command again, only this time, redirect the output to a file called: 04-root_processes.txt (use the > symbol to redirect the output)

5.   (5 pts) Write a bash shell script called 05-sortbids to sort the file "ebay.zip" (download compressed file from the course web page - too big for notepad or excel, open with textpad if you must) and save the results in 05-output in your HW03 directory.  The sort order should be ascending by AuctionID, and then within that descending by Bid, and then within that ascending by BidDateTime.  This sort order will easily allow you to determine who won any given auction, because it will be in order by increasing AuctionID, decreasing bid amount, and increasing bid date/time.  Make sure you test this carefully, since you need to use the sort key options correctly for the kind of data in the file to get this to work right.

6.   (5 pts)  Write a bash shell script called 06-month to display the name of the month (January, February, ..., December) when a month number is provided on the command-line.  For instance, you would expect the following output if the script is run with "3" as the command-line parameter:

% ./06-month 3

The name of month 3 is March.

7.   (2 pts) Use the df command with the -k option to see home much disk space is free on each partition. Re-direct this output to a file called
07-disk_space.txt
and provide a description of each column in the output of the df command.

8.   (5 pts) For scheduling a job ("/bin/test" to be run every Tuesday at 3:00 AM), write the command into "08-job.txt" that would be used.  (If you had "root" access, you would be able to schedule this job - we will get you root shortly!).

9.      (10 pts) Write a bash shell script called 09-highbid to search the file "ebay.zip" (as from above) to find the highest bid in the most recently ended auction for a user parameter AuctionID.  The user passes this AuctionID to the script as a command-line argument – the script does not prompt the user for it, in fact, it does not stop and read this information in any way after the script has been started.  Be sure to perform error-checking so that you know that the correct number of command-line arguments has been used, and generate an appropriate error message if not.  Format the output like the example below:

% ./09-highbid 1235648394

The high bid for auction 1235648394 was $255.00.
This bid was made on 05/06/2001 at 1:44:43pm
by a bidder known as ‘18273645’.

Make sure your output follows this formatting style, putting the various information on separate lines, with “$”, date ordering (MM/DD/YYYY), and time format (convert 24-hour time to am/pm format and don’t show fractions of a second) as shown above.

10.      (10 pts) Write a bash shell script called 10-netdata that executes ping and traceroute on a set of web sites (test with www.speedofheat.com, www.colostate.edu, www.biz.colostate.edu, www.cs.colostate.edu) that  you specify on the command-line when you run the script.  (traceroute is in /usr/sbin, and probably won’t run unless you give it the full path.)  Run the script and record the information for each of the performance tests listed below in a data file called 10-output in your HW05 directory.  For each destination, indicate the:

a)     Average round-trip time, indicating the date and time the results were produced.

b)      Number of hops traversed from your machine to the destination, indicating the date and time the results were produced.

c)   Names (or IP numbers) of all the points along the way from the Linux instance (10.10.102.20) to the destination.

The script should accept any number of command-line parameters, the number of parameters being the number of destinations to check.  This is the "set of web sites" mentioned above.

Format the output file so that it is easily readable and looks nice, similar to how the previous questions' output was formatted.