Revised Oct 31: Assignment 5-A - UNIX - Section 040
This assignment is the first half of Assignment 5 for Section 040 - Ian
Hand in: The telnet log sheet from the
last Hand In step in hard copy form.
You must understand Chapter 4 to do Step 2 of this
You must understand Chapter 5 to do Step 3 of this
Step 1. (Readings in Chapter 4 and Chapter 5)
Use vi to create an answer file named c4+5answers containing answers to the questions
listed in the Week 8 Reading Exercises. Put your name on the first line
of the file. Answer only the following questions:
- Answers to the Chapter 4 Reading Questions 4-2, 4-3, and 4-15 through
- Answers to the Chapter 5 Reading Questions 5-1 through 5-7, and 5-12
Make sure that your name is located at the top of the file.
Step 2. (Based on Chapter 4)
First: Before you begin this step, in your HOME directory, follow
the text and Figure 4-6 (p.266) to create the directory tree named Projects.
Make sure that this Projects tree has two sub-directories and six files
in it, exactly as it appears in the Figure. Delete any files and
directories under Projects that do not appear in Figure 4-6 on page
Practice online to develop Unix command lines that perform the following
tasks. When you have figured out the correct command lines, put the command
lines that perform these actions in a new executable Unix script file named mytree. Your commands must do the following
Put the command lines that perform the above actions into the Unix script
file, make it executable, and verify that the script file works exactly the
same as if you had typed in the commands yourself.
- Create a directory under the /tmp
directory and name it with your userid using this command line:
- Use ls to list the above directory to
make sure that it exists and is empty.
- Using the Projects directory tree you created at the beginning of
this step, copy the entire Projects directory tree to the directory
you just created: /tmp/$USER You may
need to look up online (in the Unix manual) how to use the Unix copy
command to copy one entire directory to another directory.
- Using one command, list the entire /tmp/$USER
directory tree, including all the subdirectories and files. You
should see two sub-directories and a total of six file names. You
may need to look up, in the Unix manual, the flag option to turn on a recursive
listing of a directory contents and all its subdirectories.
- Use a Unix command to locate files by name. The directory in which
to look is the new /tmp/$USER directory you just created. The name
to look for is report3 - find this file
and display its pathname.
- Remove the entire /tmp/$USER
directory tree in one command. (The entire directory must be
- Repeat Item B to verify that the directory no longer exists. (You
should get an error message about the nonexistent directory.)
- Step 3. (Based on Chapter 5)
- Test out the following tasks and script files online. When you have
confirmed and tested the command lines and scripts that do each task, append
the command lines from Item D, below, to the end of the mytree script file that you began in the step
above. (Make sure that everything still works when you execute the
modified script file!)
- Create a script similar to the programA
script file from Step 2 on page 355 of the text. Make the
following changes to the script from Step 2 on page 355:
Save the modified script as programA
and make sure it is executable by you. Your script must have only
six lines. Test it. Ensure that the modified script runs
error-free. Do not add the commands given in Step 4 on page
- replace the first line of the script with: echo "---programA starts here ---"
- replace the ps command line
with: ps -f
- replace the fourth line of the script with: echo "$0 PID is $$"
- replace the name Gene Calhoun with your own name
- Make a copy of programA and name
the new copy programB. Modify the new
Save the modified script as programB and
make sure it is executable by you. Your new script will have
exactly eight lines. Test it. Ensure that the modified
script runs error-free. Pay attention to the different types of
quotes being used (some quotes may be difficult to read, depending on
your browser and font): DoubleQuote ",
SingleQuote ', and BackQuote `
- replacing the first line with: echo
"---programB starts here ---"
- replacing the last two command lines with these four new command
echo "$0 I'm calling
echo "$0 after call to programA"
echo "$0 I'm done on `date`!"
- Issue the following four command lines:
echo "---Start testing
processes of script files ---"
echo "My shell PID is $$ and I'm calling
Ensure that the output of both scripts used in this step is
error-free. Pay attention to the quoting!
- When everything is working correctly, append the four command lines
from the immediately preceding item to the end of the mytree script file that you began in the
previous step. (Make sure that the script still runs without
- Save the two scripts you wrote for later use in Assignment 5-B.
Start telnet logging to record the
following session on your A: diskette. Perform only the following
- Display your USER environmental
- Display the date.
- Display the c4+5answers file created
in Step 1.
- Display the completed mytree script
of Steps 2 and 3.
- Execute the mytree script to
show that it works correctly and that it generates the correct output,
without unexpected errors, for all the steps in this assignment.
- Stop logging and print the telnet log file for handing in.
This one log file is the only thing you should hand in.