Assignment #3 - Basic Shell Script Assignment

Due: Friday July 13th, 11:59:59PM

Objective

To practice with basic shell scripting, as well as other Unix commands. You will write a shell script that does a variety of tasks, including manipulating files, performing commands, and writing results to an output file. We've covered all the commands you'll be utilizing in the script, so it should not be too difficult to complete this assignment. The goal of the assignment is to get basic practice with the idea of shell scripting.

Requirements

  • The script you write should be named assignment3.sh
  • The script should be set up so that it can run as an executable, and it should run using the Bourne shell (sh). You will need to run it on shell.cs.fsu.edu or linprog.cs.fsu.edu
  • Include comments at the top of your script file (#), which specify your name, the course (COP 3353), the assignment number, and the date - Points will be deducted for files with no header/identification.
  • Some of the tasks will involve writing results of commands to an output file. The output file should be named "output.txt", so whenever an instruction specifies to write results to "the output file", this is the file it refers to. The output file should be created by the script itself. You can explicitly create it, or rely on your output redirection to create it for you.
  • Create an empty directory from which to test the script. This is how your script will be tested during grading -- from a directory that contains only your script file, to begin with.
  • Any time the instructions call for printing a heading, it should look exactly like this:
    ################### Heading text ###################
    
    where you substitute the specified heading text in between the lines above. Example:
    ################### Grades Test 1 ###################
    
  • Your script should perform ALL of the tasks listed below, in order, writing results to the output file where specified. (Remember to append where necessary to avoid overwriting results of previous outputs!)

    TASKS - To be performed in order by your script

  • Copy files -- In my home directory (my username is vastola), I have a directory called ufiles. Inside this directory, there are files named:
    f1
    f2
    gradesprog
    test1
    test2
    
    Copy ONLY (there may be more files in that directory) these 5 files to your current working directory using a max of three copy commands (do not hardcode the name of a directory for the copy destination... instead, use the symbol that always refers to your current directory, no matter where your script is run from.) (Also, remember, we learned what special pathname technique we can use to get to files on other user's accounts... you do this when you submit your homeworks. You should NOT cd to this directory, just copy the files to your CWD.)

  • Grades program -- The file called gradesprog is an executable program that will run on shell.cs.fsu.edu. It takes in a set of integer grades from standard input and prints out the class average. The files test1 and test2 contain sample inputs for this program. Change the permissions on the gradesprog program so that the user (i.e. you) has full read/write/execute access, and everyone else (Group and other) have execute access. Run the gradesprog program twice, so that it accepts the data in the files test1 and test2 as input for the two respective runs. Send the output from these runs of the program to the output file (remember, this is output.txt) Print a header to the output file before each run, with header text "Grades Test 1" and "Grades Test 2" Example - After running this program, you will have added the following to the output file:
    ################### Grades Test 1 ###################
    [output from first test run of grades program]
    
    ################### Grades Test 2 ###################
    [output from second test run of grades program]
    
  • Permissions -- Change the permissions on f1 and f2 so that every entity has full permissions on the files (unsafe normally, but this is just a fun homework assignment, right? :D )

  • diff command -- The two files f1 and f2 contain similar passages of text. Use the diff command in the following three ways to find out the differences between these two files. Each time, add the output from each diff command to the output file, preceded by a header with the given text:
    Header text: "Diff command 1". Find the difference between the files where changes in the amount of white space is ignored (e.g. multiple spaces would be counted as one)
    Header text: "Diff command 2". Find the difference between the files in the simplest case (no restrictions or options/variations)
    Header text: "Diff command 3". Find the difference between the files where upper- and lower-case letters are considered equivalent

  • grep command -- Use the grep command to do the following searches on f1. Each use of grep should include the line numbers for each line reported in the results. Each time, add the output from the grep command to the output file, preceded by a header with the given text. You may have to do some research for how to do these.
    Header text: "Grep command 1". Search file1 for all occurrences of the pattern "The" that occurs at the beginning of a line.
    Header text: "Grep command 2". Search file1 for all occurrences of the exact word "who". Note that we're only looking for this word -- a word like "whomever" would not be considered a match).
  • Header text: "Grep command 3". Search file1 for all occurrences of the pattern "the". Ignore any differences in lower-/upper-case. (e.g. in this one, "The", "the", and "THE" would all match).

  • process command -- Remember that the command ps allows you to look up processes running on the system:
    Create a file called currentprocesses.txt. Print a header with the text "Process command 1" to currentprocesses.txt - this is also the only step in the assignment you'll send your output of a command to a file other than output.txt
    Then, use the ps command to report on *every* process on the system and use the "full format listing" and send those results to currentprocesses.txt
    Print another header with the text "Process command 2" to currentprocesses.txt. Then perform the process command again but this time, Filter these results so that the output will be ONLY the lines that contain the word root (remember what we can use to combine 2 commands.) Again, send the output of this process command to your currentprocesses.txt file
    Finally, run a third process command (header text Process command 3) that outputs only the lines that contain the string pclab - send the output of this once again to your currentprocesses.txt file

  • Final directory listing -- Print a header to the output file (yes, this is output.txt again), with the header text: "Directory listing" List the contents of the current working directory, using the "long listing" format, and send the results to the output file.
    Run another version of this command that lists all files that end in .txt that are in the current working directory. Use header text "Directory Listing .txt" for this.

  • Create Archive -- Create a directory in the current location called archive, then using the tar command, create a tar archive (do not use the -v flag). called allstuff.tar that contains the following files:
    	test1
    	test2
       	gradesprog 
       	output.txt
       	currentprocesses.txt 
    
    Move this tar file into the archive directory Use the gzip tool to compress the archive file that was moved into the archive directory. Do not cd into the archive directory to do this. (This means that the contents of the archive directory when you finish will be a single file called a3.tar.gz).


  • Submitting your Script

  • Make sure you are logged into shell.cs.fsu.edu and the file you want to submit is stored in your current working directory. To submit, type the following command:
     ~vastola/usub/submit3 
    where the name of your shell script is the filename. This should be:
     ~vastola/usub/submit3 assignment3.sh
    This will run a script and a C++ program that copies your file into a submission directory. The program will also give you feedback at the end -- it will display the contents of the file you just submitted to standard output. This will allow you to check to make sure that what you submitted was correct. You fmay resubmit if needed, just be aware that your last submission will be the one that is graded REMINDER: As in all courses, the academic honor code has been and will continue to be upheld. ALL programs will be run through plagiarism detection software. Make sure your work is YOUR WORK.