Assignment #3 - Basic Shell Script Assignment
Due: THURSDAY, March 31st, 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
exactly 5
files:
file1
file2
grades
t1
t2
Copy these 5 files to your current working directory using a single command (do not hardcode the name of a directory here, use a
symbol
that always refers to
your current directory.)
(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 grades 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 t1 and t2 contain sample inputs for this program.
Change the permissions on the grades program so that the user (i.e. you) has full read/write/execute access, but nobody else has any access
Run the grades program twice, so that it accepts the data in the files t1 and t2 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 file1 and file2 so that they are readable and writable by the user, and
executable-only for
group and everybody else.
diff command --
The two files file1 and file2 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 in the simplest case (no
restrictions or options/variations)
Header text: "Diff command 2". 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 3". Find the difference between the files where upper- and lower-case
letters
are considered equivalent, AND in
which all white space is ignored when comparing lines.
grep command --
Use the grep command to do the following searches on file1. 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:
Header text: "Grep command 1".
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).
Header text: "Grep command 2".
Search file1 for all occurrences of the pattern "The" that occurs at the beginning of a line.
Header text: "Grep command 3".
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).
process command -- Remember that the command ps allows you to look up processes running on the system:
Create a file called myprocess.txt. Print a header with the text "Process command 1" to myprocess.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 myprocess.txt
Print another header with the text "Process command 2" to myprocess.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 myprocess.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.
Create Archive -- Create a directory in the current location called archive, then using the tar command, create a tar archive
called myarchive.tar that contains the following files:
file1
file2
grades
output.txt
myprocess.txt
Move this archive file (myarchive.tar) 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 myarchive.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 may 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.