CSCI 330
Assignment 6
Advanced Commands
23 October 2000 Monday
The following are a set of problems that are to be solved by combining one or more commands and options. You may be required to use pipes, redirection, and/or conditional seperators. The commands required are found on the man pages and in the back of your book. Read the appropriate sections.
When solving the problems, put the command solutions in a small file and make it executable. Commands are to run under the C-shell. Set the first line to:
#!/bin/csh
This will allow you to test run a command sequence and make changes without
having to retype the whole command string. It will also allow you to use the
"here" redirection to supply instream input if required. Include a comment
line above the command line describing the problem and any info that would
help you understand the answer if you were to review it latter. When you have
solved a problem, put a comment marker in front of it and start work on the
next problem. When you have have solved all problems, mail the file to your
TA and hand in a hard copy. You may also be required to print out some of the
results of the commands and hand in the output. If this is required, it will
be indicated in the specific problem.
P1. Using the here redirection feature to supply the commands for at to schedule, schedule at to run the finger command and list all processes running. These are to run in an hour and 17 minutes from the time the at command is issued.
P2. Using the here redirection feature to supply the commands for at to schedule, schedule at to run a single line command sequence that invokes who, sorts its output and then counts (wc) the number of unique users (words) logged on. Schedule a second at command sequence that simply runs who and counts (wc the total number of logons (words). Schedule the job to run at Saturday at 2:35 in the afternoon.
P3. Once both problems are scheduled, use at to list what is in the schedule queue and redirect output to a file. Print the file with the at output, and hand in seperately. Do NOT mail the at listing output to your ta.
P4. When you have tested and finished your at problems, use atrm and the appropriate option to clear all jobs from the at schedule queue, otherwise you will be mailed several files of useless data when the commands actually run.
P5. Set the local variable "lines" to 173, Assuming a page has 50 lines, use expr to calculate the number of whole pages represented by 173 lines. On the same command line, use expr to calculate the number of lines on the last page. Look at the divide and mod functions of expr.
P6. As part of a single command line sequence, set the local variable "num" to 7 and add the current process id to it. See the book for the name of the process id variable. Assign the output of the command to the local variable total. If the expression ran correctly , echo out the contents of total.
P7. Write two versions of the find command and for each pipe their output to the wc to count the number of files found. For the first version, use find to generate a list of all files under /usr and count them. For the second version, search only the the filesystem that /usr is directly mounted on. Do not cross any mount points. Redirect output to the terminal but redirect error messages to /dev/null. You will have to use the parens to seperate output and errors. This may take several minutes to run, be patient.
The count should be different with the first version returning a much larger number.
P8. Use find to look in my data directory for all files called fdata and run grep on each file and look for lines beginning with #rem Use absolute path to specify the path to my data directory (~berezin/data). The regular expression to use with grep is "^#rem"
P9. Copy my data directory to your work directory. Read about the recursive option of cp. If the copy was successful, find all files called Core in your copy of the data directory and delete them. Code the copy (cp) and the find as a single command line sequence. Use the conditional command seperators to test the success of cp before attempting to run the find. Also, use the conditional run option of find to prompt the user before deleting each Core file
Remember to delete the directory when you are done with this command.
P10. Look in my data directory ( ~berezin/data ) and find all files that have the same inode as data1. Use ls -i and cut to get the inode of data1 and assign it to a variable. Then use find to search for other filenames for that inode#.
P11 Find all files in my data directory ( ~berezin/data ) that have more than 3000 bytes. Remember, you can specify greater and less than specified value by putting a + or - in front of the numeric value.
P12 Find all files in my data directory that do not belong to me (berezin). You may put an ! in front of an option to invert its meaning.
P13 Find all files in my data directory ( ~berezin/data ) that have a file modification time greater than a year or less than a week.
P14. tar all of your files in your 330 directory and all subdirectories. Use an absolute path to specify your 330 directory. Save them to a file called 330.tar You can run this inside your 330 directory, however you will get an error message. Redirect the output messages from tar to the file tarout and the error messages to tarerr. You do not need to hand these in but look through them. Delete the 330.tar file when you are done.
P15. tar my data directory and expand it in you own 330 directory. Do not use absolute paths. However you should start above my data directory and tar it. Use two tars and a pipe between them. This technique is often used to transfer data between systems. To do this you will tar the directory of interest and send the output of tar to standard out. To specify standard out, you use the filename option and specify - (hyphen) as the name of the output file. You then pipe the output to the input of a second tar. Again you use the filename option and - (hyphen) as the name of standard input. However, in order to extract a tar file (untar) in a new location, you must already be at the new location. So you must cd to new location running the second tar. Since you can't directly insert a cd command between two command whose i/o is piped together, you have to trick the Unix system. You can use parens () to perform the required cd and the second tar that will untar from standard input.
Example: the following command sequence will cat a file in the current directory and pipe it to sort after changing to a subdirectory. The results will be that the output file of sort is created in the subdirectory. And when the sequence is done, you will still be in your starting directory
cat file1 | ( cd subdir; sort > sout )
Your command line must do the following steps in order.