Difference between revisions of "CSC220 Homework 1 2010"
(Created page with '<center> <font size="+2">Page under construction!</font> <br \>300px </center>') |
|||
(28 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | < | + | <tanbox> |
− | < | + | This assignment is due on Wednesday, Sept. 22, at 11:59 p.m. + 1 minute. Programs submitted passed the deadline will not be collected or graded.<br />You can work on this assignment individually or in a group of two. If you decide to work in pair, make sure you have read the very good article on [http://maven.smith.edu/~jfrankli/111s08/pairProgramming2000.pdf Pair Programming]. If you work in pair, you only need to submit one program for each question. Make sure the names of both programmers appear in the header of the script. |
− | < | + | </tanbox> |
− | </ | + | |
+ | <br /> | ||
+ | <br /> | ||
+ | __TOC__ | ||
+ | <br /> | ||
+ | <br /> | ||
+ | |||
+ | =Documentation= | ||
+ | |||
+ | * Each submitted script should have a header with | ||
+ | *# the typical link to the /bin/bash shell | ||
+ | *# the name of the script | ||
+ | *# the name of the programmer or programmers | ||
+ | *# the current date | ||
+ | *# a description of what the script does | ||
+ | *# an example of how to call the script (especially if it requires command line parameters) | ||
+ | |||
+ | * Do not hesitate to use comments inside the script to indicate where the different parts/sections are, and what is going on with the code. | ||
+ | |||
+ | =Problem #1= | ||
+ | |||
+ | Write a script that lists all the users on grendel by year of last access to their account. The output should list all the years starting in 2005 and ending in 2010. | ||
+ | |||
+ | An example of the output could be | ||
+ | |||
+ | <code><pre> | ||
+ | 2005: | ||
+ | |||
+ | 2006: | ||
+ | |||
+ | drwx------ 4 root root 16384 Jul 11 2006 lost+found/ (not really a user but that is ok) | ||
+ | drwxr-xr-x 3 flatland users 4096 Jul 11 2006 flatland/ | ||
+ | drwxr-xr-x 7 bmikic faculty 4096 Jul 11 2006 bmikic/ | ||
+ | drwxr-xr-x 23 102155 users 4096 Aug 3 2006 mmartin2/ | ||
+ | |||
+ | 2007: | ||
+ | |||
+ | drwxr-xr-x 3 root root 4096 Apr 18 2007 keterhome/ | ||
+ | drwxr-xr-x 155 cleung users 12288 May 18 2007 snida/ | ||
+ | drwxr-xr-x 43 zeno users 20480 Aug 14 2007 zeno/ | ||
+ | |||
+ | etc... | ||
+ | |||
+ | </pre></code> | ||
+ | |||
+ | * store your script in a file called '''allUsersByDate.sh''' and submit it as follows: | ||
+ | |||
+ | submit hw1 allUsersByDate.sh | ||
+ | |||
+ | :(For those of you who have never used our class system before, you need to be logged in your 220a-xx account to submit your programs. They get copied to the instructor's directory automatically, and time-stamped. You can submit a program as many times as you want, but be aware that each submission overwrites the previous contents of a file.) | ||
+ | |||
+ | =Problem #2= | ||
+ | |||
+ | * Same as Problem #1, but this time the output should be just the user's name, not the whole line showing the permissions, date, etc. | ||
+ | |||
+ | * Your output should not include the ''lost+found'', which is not a user but just a regular directory. | ||
+ | |||
+ | :Example: | ||
+ | |||
+ | <code><pre> | ||
+ | 2006: | ||
+ | |||
+ | flatland/ | ||
+ | bmikic/ | ||
+ | mmartin2/ | ||
+ | |||
+ | </pre></code> | ||
+ | |||
+ | * Store your script in a file called '''allUsersByDate2.sh''' and submit it as follows: | ||
+ | |||
+ | submit hw1 allUsersByDate2.sh | ||
+ | |||
+ | * Hints: using the '''cut''' utility is key here. This [http://www.thelinuxblog.com/using-cut-shellscript-string-manipulation/ page] has useful examples. | ||
+ | |||
+ | =Problem #3= | ||
+ | |||
+ | * Write a script that contains all the answers to the questions in [[CSC220 Lab 1 2010 | Lab #1]], starting with Section 2. | ||
+ | For Section 4, your script should get the log file from the Url specified and store it in the ''current directory'', which ever one it is. For Section 5, Question 4, we'll assume that ''today'' is '''Sept. 14, 2010'''. For Section 6, make your script execute the '''stdouterr.py''' program located in '''/Users/classes/220a/bin/stdouterr.py''' | ||
+ | |||
+ | * Make your script output (echo) the name of the section and the question before each output. For example | ||
+ | |||
+ | Path-Related Section: Question 1 | ||
+ | |||
+ | /Users/classes/220a/ | ||
+ | |||
+ | Path-Related Section: Question 2 | ||
+ | |||
+ | 100e 102b 103a 105b 107a 111b 220a 240a 352b 400b archive_old_accts.pl testd3 | ||
+ | 102a 102c 105a 105c 111a 111c 231a 249b 353a acctlist OLD | ||
+ | |||
+ | * Store your script in a file called ''lab1answers.sh'', and submit it as follows: | ||
+ | |||
+ | submit hw1 lab1answers.sh | ||
+ | |||
+ | |||
+ | <bluebox>WARNING! When I execute and test your script, I will not be in your home directory, but in a different directory, somewhere in /Users/classes/220a/handin/... Therefore, make sure that you '''test''' your script by running it from a directory other than your main directory. For example, you can create a new directory in your account, copy your script there, cd to the directory, and run the script from there. | ||
+ | </bluebox> | ||
+ | |||
+ | =Problem #4 = | ||
+ | |||
+ | * Try this command: | ||
+ | |||
+ | du /var | ||
+ | |||
+ | : and observe the output: | ||
+ | |||
+ | '''du /var ''' | ||
+ | |||
+ | 4 /var/account | ||
+ | du: cannot read directory `/var/gdm': Permission denied | ||
+ | 4 /var/gdm | ||
+ | 4 /var/preserve | ||
+ | 4 /var/local | ||
+ | 4 /var/report | ||
+ | 4 /var/opt | ||
+ | du: cannot read directory `/var/empty/sshd': Permission denied | ||
+ | 4 /var/empty/sshd | ||
+ | 8 /var/empty | ||
+ | 260 /var/www/icons/small | ||
+ | 944 /var/www/icons | ||
+ | |||
+ | * du stands for ''disk usage''. What you get is a list of all the directories in the /var directory (typically programs and libraries used by Linux), prefixed by the number of blocks (typically kilobytes) used by each directory. Some directories are not readable by regular users, so we may get "cannot read directory X: Permission denied" messages for some of them. | ||
+ | |||
+ | * Write a script that prints out the 10 largest directories or subdirectories in the /var directory. Read the '''man'''ual page for sort to figure out how to sort correctly. | ||
+ | |||
+ | * Call the script biggestVar.sh and submit it as follows: | ||
+ | |||
+ | submit hw1 biggestVar.sh | ||
+ | |||
+ | =Problem #5, Optional and Extra Credit= | ||
+ | |||
+ | * Try the -h switch for the '''du''' command. See how the output is more ''humanly'' readable? | ||
+ | |||
+ | * Modify the biggestVar.sh script so that it outputs the 10 largest directories, but with the size showing up in the ''human readable'' format. | ||
+ | |||
+ | * Call your script '''biggestVar2.sh''' and submit it as follows: | ||
+ | |||
+ | submit hw1 biggestVar2.sh | ||
+ | |||
+ | |||
+ | =Fun Stuff (not for the homework)= | ||
+ | |||
+ | * Login to your 220a-xx account | ||
+ | * Try this at the prompt: | ||
+ | |||
+ | |||
+ | cat > dummy | ||
+ | hello there! | ||
+ | how are you? | ||
+ | Ctrl-D ''(press Control-D to simulate the End-Of-File character)'' | ||
+ | mail -s "hello from my 220a account" 220a-'''xx'''@cs.smith.edu < dummy | ||
+ | |||
+ | :'''Make sure you replace xx by your two-letter Id.''' | ||
+ | |||
+ | * Now check your 220a-xx mail by typing | ||
+ | |||
+ | mail | ||
+ | |||
+ | :at the prompt. | ||
+ | |||
+ | * You should see one message in your mailbox. It might be strange to look at your mail in something that is not a browser, but at some point in time, dealing with email was from the command line, in text mode! :-) | ||
+ | |||
+ | * Type '''1''' to see the first message in your box. Verify that its contents is what you typed above. | ||
+ | * You can type '''q''' to exit from the mail utility and return to the prompt. | ||
+ | * I was about to ask you to write a script that would send email to all the students in 220a, but decided it would be more bothersome to everybody than useful. So I will leave this as something fun for you to consider. This is the way mass-mailing is done. With a loop, you can send email to tons of people! | ||
+ | |||
+ | |||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | [[Category:CSC220]][[Category:Homework]] |
Latest revision as of 13:38, 20 September 2010
This assignment is due on Wednesday, Sept. 22, at 11:59 p.m. + 1 minute. Programs submitted passed the deadline will not be collected or graded.
You can work on this assignment individually or in a group of two. If you decide to work in pair, make sure you have read the very good article on Pair Programming. If you work in pair, you only need to submit one program for each question. Make sure the names of both programmers appear in the header of the script.
Contents
Documentation
- Each submitted script should have a header with
- the typical link to the /bin/bash shell
- the name of the script
- the name of the programmer or programmers
- the current date
- a description of what the script does
- an example of how to call the script (especially if it requires command line parameters)
- Do not hesitate to use comments inside the script to indicate where the different parts/sections are, and what is going on with the code.
Problem #1
Write a script that lists all the users on grendel by year of last access to their account. The output should list all the years starting in 2005 and ending in 2010.
An example of the output could be
2005:
2006:
drwx------ 4 root root 16384 Jul 11 2006 lost+found/ (not really a user but that is ok)
drwxr-xr-x 3 flatland users 4096 Jul 11 2006 flatland/
drwxr-xr-x 7 bmikic faculty 4096 Jul 11 2006 bmikic/
drwxr-xr-x 23 102155 users 4096 Aug 3 2006 mmartin2/
2007:
drwxr-xr-x 3 root root 4096 Apr 18 2007 keterhome/
drwxr-xr-x 155 cleung users 12288 May 18 2007 snida/
drwxr-xr-x 43 zeno users 20480 Aug 14 2007 zeno/
etc...
- store your script in a file called allUsersByDate.sh and submit it as follows:
submit hw1 allUsersByDate.sh
- (For those of you who have never used our class system before, you need to be logged in your 220a-xx account to submit your programs. They get copied to the instructor's directory automatically, and time-stamped. You can submit a program as many times as you want, but be aware that each submission overwrites the previous contents of a file.)
Problem #2
- Same as Problem #1, but this time the output should be just the user's name, not the whole line showing the permissions, date, etc.
- Your output should not include the lost+found, which is not a user but just a regular directory.
- Example:
2006:
flatland/
bmikic/
mmartin2/
- Store your script in a file called allUsersByDate2.sh and submit it as follows:
submit hw1 allUsersByDate2.sh
- Hints: using the cut utility is key here. This page has useful examples.
Problem #3
- Write a script that contains all the answers to the questions in Lab #1, starting with Section 2.
For Section 4, your script should get the log file from the Url specified and store it in the current directory, which ever one it is. For Section 5, Question 4, we'll assume that today is Sept. 14, 2010. For Section 6, make your script execute the stdouterr.py program located in /Users/classes/220a/bin/stdouterr.py
- Make your script output (echo) the name of the section and the question before each output. For example
Path-Related Section: Question 1 /Users/classes/220a/ Path-Related Section: Question 2 100e 102b 103a 105b 107a 111b 220a 240a 352b 400b archive_old_accts.pl testd3 102a 102c 105a 105c 111a 111c 231a 249b 353a acctlist OLD
- Store your script in a file called lab1answers.sh, and submit it as follows:
submit hw1 lab1answers.sh
Problem #4
- Try this command:
du /var
- and observe the output:
du /var 4 /var/account du: cannot read directory `/var/gdm': Permission denied 4 /var/gdm 4 /var/preserve 4 /var/local 4 /var/report 4 /var/opt du: cannot read directory `/var/empty/sshd': Permission denied 4 /var/empty/sshd 8 /var/empty 260 /var/www/icons/small 944 /var/www/icons
- du stands for disk usage. What you get is a list of all the directories in the /var directory (typically programs and libraries used by Linux), prefixed by the number of blocks (typically kilobytes) used by each directory. Some directories are not readable by regular users, so we may get "cannot read directory X: Permission denied" messages for some of them.
- Write a script that prints out the 10 largest directories or subdirectories in the /var directory. Read the manual page for sort to figure out how to sort correctly.
- Call the script biggestVar.sh and submit it as follows:
submit hw1 biggestVar.sh
Problem #5, Optional and Extra Credit
- Try the -h switch for the du command. See how the output is more humanly readable?
- Modify the biggestVar.sh script so that it outputs the 10 largest directories, but with the size showing up in the human readable format.
- Call your script biggestVar2.sh and submit it as follows:
submit hw1 biggestVar2.sh
Fun Stuff (not for the homework)
- Login to your 220a-xx account
- Try this at the prompt:
cat > dummy hello there! how are you? Ctrl-D (press Control-D to simulate the End-Of-File character) mail -s "hello from my 220a account" 220a-xx@cs.smith.edu < dummy
- Make sure you replace xx by your two-letter Id.
- Now check your 220a-xx mail by typing
- at the prompt.
- You should see one message in your mailbox. It might be strange to look at your mail in something that is not a browser, but at some point in time, dealing with email was from the command line, in text mode! :-)
- Type 1 to see the first message in your box. Verify that its contents is what you typed above.
- You can type q to exit from the mail utility and return to the prompt.
- I was about to ask you to write a script that would send email to all the students in 220a, but decided it would be more bothersome to everybody than useful. So I will leave this as something fun for you to consider. This is the way mass-mailing is done. With a loop, you can send email to tons of people!