CSC220 Homework 1 2010

From dftwiki3
Revision as of 14:45, 14 September 2010 by Thiebaut (talk | contribs) (Problem #3)
Jump to: navigation, search


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 Questions: Question 1
 
/Users/classes/220a/

Path-Related Questions: 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
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.

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

  • 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!