| |
Assignment 5-A - UNIX
This assignment is for sections taught by Ian Allen. It is the first
half of Assignment 5.
-
Hand in:
- One printed and hand-annotated telnet session log file
in hard copy form. For full marks, follow the Assignment
Submission Standards. In particular, make sure you use Courier
font and annotate your output (see below) before you hand it in.
- Preparations:
- You must complete the work in the previous Chapters (1, 2,
13, 7, and 3) as well as Chapters 4 and 5 in your Unix text before doing this
assignment.
-
Step 1. (Readings in Chapter 4 and Chapter 5)
Use the vi
text editor to type the answers to the following Chapter Reading/Study
Exercises into the file
named my5answers
in your home directory. Number each answer clearly. You will find the Chapter Exercises under the Unix
button on the course page.
Put your name and your Algonquin e-mail address at the top of
the file.
Answer the Chapter 4
Exercises 4-1, 4-2, 4-3, 4-5, 4-6, and 4-14 through
4-19.
Answer the Chapter 5
Exercises 5-3 through 5-8, and 5-12
through 5-18.
Put your name and your Algonquin e-mail address at the top of this file.
Number each answer clearly.
Step 2. (Shell Script my5tree)
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
266.
Practice online to develop Unix command lines and/or pipelines that perform the following
actions, one-by-one. As you figure out each correct command line, add the command
line to a new executable Unix script file named my5tree in your home directory.
Test the script after each added line. Add lines to the script file one
at a time; do not put all the actions in the script and then try to debug it!
Notes on this script:
- Some actions may be done by a
single Unix command; some actions may need a pipeline of one or more Unix
commands. Do not add extra commands to this script. Do exactly
what is requested and no more. (For example, do not change working
directories unless the action requires it.)
- The actions below must not depend on
the script running in any particular working directory. The script
should work no matter what your current working directory is.
- Your actual account or userid and home directory name must not appear in
any pathnames used in the
script. Use the appropriate environment variables any time you need these
values. (For example, use $HOME not /shome/abcd0001.)
Here are the actions your script must execute:
- The very first line of the script must indicate what program is to run
the script:
#!/bin/sh -u
- Next, include one or more comment lines with your name, your Algonquin
email address, and the
date you began creating the script.
- Use an echo command to display the following text on the screen:
echo "$0 Start of script for $USER in $PWD on
`date`" Pay attention to the kind of quotes used in this line!
Make sure the three shell variables expand correctly and that the
date command executes. (Note the use of back-quotes around
`date`.)
- Create a directory under the /var/tmp
directory and name it with your userid using the contents of the USER environment
variable: /var/tmp/$USER
- Use ls to list the above directory to
make sure that it exists and is empty. (Do not change your current
working directory!)
- Using the Projects directory tree you created in your home
directory at the beginning of
this step, use a single Unix command to recursively copy your entire Projects directory tree to the directory
you just created: /var/tmp/$USER You may
need to look up online (in the Unix manual) the option that makes the Unix copy
command copy one entire directory recursively to another directory.
(Look for the word recursive.)
- Using one single Unix command, list the entire /var/tmp/$USER
directory tree, including all the subdirectories and files. You
should see two sub-directories and a total of six file names in the output,
exactly like Figure 4-6. You
may need to look up online (in the Unix manual) the option to turn on a recursive
listing of a directory and all its subdirectories.
- For this next action, use a Unix command that locates files by name. The directory in which
to look is the new /var/tmp/$USER directory you just created. The name
to look for is report3 - find this file
by name and display its pathname.
- Create name /var/tmp/$USER/rep3 as a
second name for the report3 file you
found in the previous action. The new name must be a link to the same
file; it must not be a copy of the file.
- Use the -i and -l
options of the ls command to
show a long listing including the inode numbers of the two file names in
the previous action. (The inode numbers and all file details should be the
same, since they are the same file!)
- Remove the entire /var/tmp/$USER
directory tree using a single Unix command. (The entire directory must be
removed.)
- Use the ls command to verify that the directory
in the previous action no longer exists. (You
should get an error message about the nonexistent directory.)
Put the command lines that perform the above actions into the Unix script file named my5tree in your home directory, make it executable, and verify that the script file works exactly the
same as if you had typed in the commands yourself. The only error message you should see is the one from the final
ls command in the script.
Does the script follow the Notes given at the start of this step?
Step 3. (Shell Script scriptA)
Write and test the following script file. Save this script - you will use
it again in the next assignment.
Copy the six-line programA
script file from Step 2 on page 355 of the text to a new file named scriptA. Make the
following changes to the new file:
- Replace the first line of the script (echo hello) with:
echo "$0 --- scriptA PID $$ in $PWD starts here ---"
- Replace the ps command line
with: ps -f
- Replace the fourth line of the script (another echo) with:
echo "$0 scriptA's PID is $$"
- Replace the name Gene Calhoun with your own name
- Add this line to the bottom of the script:
echo "$0 scriptA PID $$ is done on `date`!"
- Insert a correct #!/bin/sh -u
line at the start of the
script.
Save the modified script as scriptA and make sure it is executable by you. Your
new script must have only
seven executable lines plus the #!/bin/sh -u line at the top.
Pay attention to the quoting! Test it. Ensure that the modified script runs
error-free. Do not add the commands given in Step 4 on page
356. Pay attention to the different types of
quotes being used (some quotes may be difficult to read in this web page, depending on
your browser and font): DoubleQuote ",
SingleQuote ', and
BackQuote `
Step 4. (Shell Script scriptB)
Write and test the following script file. Save this script - you will use
it again in the next assignment. This script requires scriptA
to work. Make a copy of the eight-line script scriptA
from Step 3 and name
the new copy scriptB. Modify the new
copy by making the following changes to the new scriptB
file:
- Inside scriptB, change the every word
scriptA to scriptB.
(Keen students will find a quick way to do this using one line in vi
on page 776.)
- Delete the line that echoes the contents of the HOME
environment variable.
- Replace the b= line containing your name and the echo command line that
follows it with these three new command lines (delete those two lines; add
the following three new ones in their place):
echo "$0 scriptB PID $$ I'm calling scriptA now"
./scriptA
echo "$0 scriptB PID $$ after call to scriptA"
Save the modified script as scriptB and
make sure it is executable by you. Your new script will have
exactly eight lines. Test it in the same directory that contains scriptA.
(This script calls scriptA.)
Ensure that the modified
script runs error-free. Pay attention to the different types of
quotes being used.
Step 5. (Shell Script scriptC)
Write and test the following script file. Save this script - you will use
it again in the next assignment. This script requires scriptB
to work.
Make a copy of the eight-line script scriptB
from Step 4 and name
the new copy scriptC. Modify the new
copy by making the following changes to the new scriptC
file (and do these changes in this order):
- Inside scriptC, change every
occurrence of word
scriptB to scriptC.
- Inside scriptC, change every
occurrence of word
scriptA to scriptB.
Test
scriptC in the same
directory that contains scriptB.
(This script calls scriptB.)
Ensure that the output of all the scripts used in this step is
error-free. (To debug the script output you may need to pipe
the output into a command that pages the output for you; or, you can
redirect the output to a file and look at it there.)
Save these three scripts for use in the next assignment.
Step 6. (Creating the Telnet Log File)
You need to have done all the readings, completed all the prerequisite
Chapters, and completed all previous steps of this Assignment to do this
logging Step.
Login to Unix and then
turn on telnet logging to record
the following Unix session on your A:
diskette or on your N: drive. When asked to display the
contents a file or script, use the cat
command. (For full marks, do not use an editor or any commands that paginate the file,
since the pagination mis-formats the display of the file in the log.) Perform the following actions for
the log file:
- Set your shell prompt to be your Algonquin userid. (You learned
this in Chapter 1.)
- Display the contents of your USER environment
variable.
- Display the current date.
- Display the contents of the my5answers file created
in Step 1.
- Display the contents of the completed my5tree script
of Step 2.
- Execute the my5tree script to
show that it works correctly and that it generates the correct output,
without unexpected errors.
- Display the contents of the scriptA
file of Step 3.
- Display the contents of the scriptB
file of Step 4.
- Display the contents of the scriptC
file of Step 5.
- Execute the scriptC file to show that
it (and the scripts it calls) works correctly.
Turn off telnet logging. Print the Telnet log file using a
monospace (Courier) font.
Step 7. (Annotating the Telnet Log File)
Annotate your printed Telnet log file output by hand as follows:
- Take a pen or marker and draw long, page-width lines between each of
the numbered actions you performed in the previous step.
- Write in (using pen or marker) the number of the action beside each
of the actions. Use the action numbers given in the previous
step.
- Highlight or underline each of the Unix command lines
you typed to the shell to do the actions in the previous step. Do not
highlight the output of the command lines. Highlight
only the Unix command lines that you typed in.
There is only one telnet session log file to hand in. It comes
from Step 6. Do not log or hand in anything else other than the one log
file from Step 6. Make sure you annotate the log file by hand as required in Step
7.
|