----------------------- Exercise #4 for DAT2330 due November 30, 2004 ----------------------- -Ian! D. Allen - idallen@idallen.ca Remember - knowing how to find out an answer is more important than memorizing the answer. Learn to fish! RTFM! (Read The Fine Manual) Global weight: 5% of your total mark this term Due date: 10h00 (10am) Tuesday November 30, 2004. The deliverables for this exercise are to be submitted online on the Course Linux Server using the "datsubmit" method described in the exercise description, below. No paper; no email; no FTP. Late-submission date: I will accept without penalty exercises that are submitted late but before 10h00 (10am) on Thursday, December 2. After that late-submission date, the exercise is worth zero marks; but, it must still be completed and submitted successfully to earn credit in the course. Exercises submitted by the *due date* will be marked online and your marks will be sent to you by email after the late-submission date. A sample answer will be posted online after the late-submission date. This exercise is due on or before 10h00 Tuesday November 30, 2004. Exercise Synopsis: You will use "vim" to create some executable shell scripts. Where to work: Do your Unix command line work on the Course Linux Server. Do not use ACADUNIX. The files you work on will remain on the server even after you log off. Do not erase your files after submission; always keep a spare copy of your exercises. WARNING: Do not attempt this exercise on a Windows machine - the text file format is different. You must connect to and work on Unix/Linux. Note that you may connect to the Course Linux Server *from* a Windows machine (using PuTTY); however, you may not use the Windows machine itself to do your work. Use the vim editor on the Course Linux Server. Location of the course notes on the Course Linux Server: You can find a copy of all the course Notes files on the Linux Server under directory: ~idallen/public_html/teaching/dat2330/04f/notes/ You can copy files from this directory to your own account for modification or study, if you like. (To avoid plagiarism charges, you must credit any material that you copy and submit unchanged.) Exercise Preparation: A. Know where to find an online copy of all the course Notes on the Course Linux Sever. (See above and in course_linux_server.txt) Do not use the ACADUNIX computer for this exercise. B. Do *not* create temporary files if using a Unix pipe would work. C. If you create any temporary files: 1. you must create them under the public /tmp/ directory, 2. the names must be unique (contain the process ID), 3. you must remove the files when you are done You must never assume that the current directory is writable. -------------------------------------------------------- Exercise Details (to be done on the Course Linux Server) -------------------------------------------------------- Have you done all the preparation steps? If not, go back and do them. Using VI/VIM, edit and create new executable script files on the Course Linux Server. The spelling of each script file name must be exact, othewise it won't be marked. The spelling must be exact. Exact! -------------------- For all script files -------------------- Make sure each executable script file you write starts with the nine necessary parts of a DAT2330 executable shell script, as given by the script_style.txt file under Notes. Make sure the file is executable (at least by you, the owner) and does *not* have group or other write permissions turned on. Follow the format given in the script_style.txt file under Notes. Print error messages and exit the script on bad input. --------------------------- Script name: moreweather.sh --------------------------- Marks: 5 of 5% Enhance your myweather.sh script from the previous exercise (#3) as follows: Instead of fetching and printing the weather information just once, add a loop that executes as long as the current user ($USER) is logged in. Once the current user logs out, the loop must finish and the script must print a message saying that the user logged out and the script is done. Inside the loop, fetch the current weather information and output the weather information line only if the weather information has changed since the last time the loop was run. If the weather value has not changed, no output will be done during this iteration of the loop. The weather information should always print the first time the loop runs. Whether anything prints on subsequent iterations depends on whether or not the new value of the weather field changes for that iteration. The loop should run no more often than once per hour. Sleep for an hour at the loop end to ensure that the loop does not repeat right away. The loop should iterate at most once per hour. Enhance your Exercise #3 weather output by putting the current date and time at the start of the line that produces the output, so you know when each line of output appears. This new script must also follow all the basic input and validation specifications of Exercise #3. * Testing Since the Environment Canada weather page is updated only once per hour, testing your script could take a long time if you had to wait an hour for real weather changes to appear. To test your script more quickly, make these two changes for testing and debugging only: 1. Change the sleep time to 10 seconds instead of an hour. 2. Add a line of shell script code that fetches the current weather value from a text file instead of from the Environment Canada web page. For example, x=$( cat testvalue ) will put the contents of the file testvalue into the shell variable named x. Now, you need only update the value in the text file to have your script get a new value, and you can change the value as often as you like to test your script. Every new value should result in a new line of output from your script after 10 seconds. Make sure this works: $ echo 123 >testvalue $ ./moreweather.sh yul temperature & # background or run in another window [1] 4698 Wed Nov 24 14:24:20 EST 2004 The temperature in YUL - Montréal - is 123 $ echo 222 >testvalue Wed Nov 24 14:24:40 EST 2004 The temperature in YUL - Montréal - is 222 $ echo 111 >testvalue Wed Nov 24 14:24:50 EST 2004 The temperature in YUL - Montréal - is 111 The script must only output one line when the weather value changes. If the value does not change, no line should be output. Once you have verified that the logic in your script is correct and that the output follows the specifications, you can comment out or remove the debugging code. My sample solution for this exercise added about 10 lines of new shell code to the Exercise #3 solution to handle the new requirements, for a total of about 66 lines of shell code (plus lots of comments and blank lines to make it readable). * Hints and References Notes file wait_login.sh.txt has code relevant to this exercise. ------------- Documentation ------------- Follow the new block-comment style given in the script_style.txt file under Notes. Script lines with incorrect or missing comment lines will not be marked. ---------- Submission ---------- Submit all the executable script files for marking as Exercise 04 on the Course Linux Server, using the following *single* datsubmit command line: $ datsubmit 04 moreweather.sh This "datsubmit" program will copy all the selected files to me for marking. Always submit all your files at the same time. Do not delete your copies; keep them. Verify that you submitted all your files. P.S. Did you spell all the label fields and file names correctly?