CS197U: A Hands-on Introduction to Unix

Assignment 5 : Due Oct 22, 2015 at 3:45pm

This assignment will teach you about using Subversion repositories for synchronizing code, setting up cron jobs, and more bash/awk scripting. See Lectures 5-8 for more information.

You will again need to consult `man', earlier lectures, and also the web for finding out how to accomplish the tasks. The tasks are sufficiently complex, so you will need to find out some things on your own. There is often more than one correct approach.

Part 1: Tracking your course webpage (3pts)

1. Make a new directory called 'assign-5' in your home directory: /courses/cs100/cs197/USERNAME
copy files from assignment directory: cp -r /courses/cs100/cs197u/cs197u/assignments/assign-5/* /courses/cs100/cs197u/USERNAME/assign-5/

2. Retreive the webpage from Ed-Lab webpage by typing: wget -N http://www-edlab.cs.umass.edu/cs197u/index.html

3. Rename this webpage from index.html to old.html , what is the command you use? Wait for 10 minutes, and retrieve the webpage again.

4. What is the command that you use to check the difference between index.htmland old.html? What is the output when they are different?

5. Edit the shell script named check.sh by inserting what you have done for steps 3 and 4 (no need to wait 10 minutes), and it will send you email when the webpage is updated.

6. Set up a cron job that runs check.sh (remember to specify full path of your check.sh) at the 15th minute of every hour in October. [Hint: the default crontab editor is emacs, check out the slides and see how to save and exit the file.]
Write down your commands/output for steps 4 and 6 into answers-5.txt.

You'll get most of the points when I receive an email sent from your ed-lab account.

Part 2: What do these commands do? (3pts)

grep -no "[aeiouAEIOU]" text/hamlet.txt|
awk -F":" 'BEGIN{x=1; y=0} { if(x!=$1) {print "x " x " has " y " y"; x = $1; y = 1} else y += 1}'


Note: grep -no is short for grep -n -o.

1. On the web, read about if statements in awk, and spend some time understanding what the command above does. Run the full command from within your assign-5 directory, so that it finds text/hamlet.txt. Use less after each pipe to understand what the code does. The anonymous variable names x and y are intentional to not make it obvious what the code is doing. Figuring out what they stand for is part of the task. Describe in 1 sentence what this command actually prints out. Write your answer into answers-5.txt. Don't use any variable names in your description.

2. Redirect the output of the above command into a file. Use the sort command with some flags to sort this file in decreasing order of y. What is the largest x value for the largest y value? Which command did you use? Write your answers into answers-5.txt.

Part 3: Processes and Vim (2 pts)

1. What are the commands (in one line) that list root's oldest 20 processes with process IDs?

2. Redirect your output to a file named process.txt, and open it with vim.

3. In the command mode, what is the command to delete 3 lines at once, what is the command to copy 4 lines at a time, and what is the command to paste what you just deleted or copied?

4. First move to line 1 of process.txt, delete three lines with the above command. Move to line 3 (of the updated file), paste the three lines just deleted. Move to line 7 (of the updated file), copy the following four lines at once; move to line 10 (of the updated file), paste what you just copied. Save the updated process.txt and quit vi.

Write your answers of steps 1 and 3 into file answers-5.txt. You should not edit process.txt within the insert mode.

Part 4: Checking out the repository; archiving and compressing files. (2pts)

1. Make sure your current directory is still: /courses/cs100/cs197u/USERNAME/assign-5;
2. Check out the svn repository into this assign-5 directory
repository path for svn checkout command:/courses/cs100/cs197u/USERNAME/svn;
You will get a new directory also named svn in your assign-5 directory. *Hint*: Use file:// instead of svn+ssh:// to check out.

3. Copy your answers-5.txt, check.sh, process.txt into this local copy with this command:
cp /courses/cs100/cs197u/USERNAME/assign-5/*.txt /courses/cs100/cs197u/USERNAME/assign-5/svn/
cp /courses/cs100/cs197u/USERNAME/assign-5/*.sh /courses/cs100/cs197u/USERNAME/assign-5/svn/
4. Archive and compress the three files into one tarball named hw5.tar.gz *Hint*: Check out how to usetar command.

5. Add the above four files (hw5.tar.gz, answers-5.txt, process.txt, check.sh) to the repository using the svn add command

6. Commit the changes to repository using the svn commit command

7. Don't add any output files to the SVN repository (the path specified in step 2). You will lose 0.5 point if you change anything in the SVN repository (and might fail to submit your homework through SVN commands). Just commit your changes to files to the SVN repository

You will know that you have successfully committed files if you get a message which ends with: Committed revision <some number>.

Submission

Important Notice:
Besides Part-4 (commit answers to SVN repository), you should also leave your answers in the assignment directory /courses/cs100/cs197u/USERNAME/assign-5/
We'll collect your answers there. They are:

  • answers-5.txt
  • process.txt
  • check.sh
  • hw5.tar.gz

  • For part-4, I will consider the latest version of files committed to your repository before the deadline as your final submission.
    You can always double check what files are in the SVN repository by using the command: svn list .