Difference between revisions of "CSC220 Lab 1 2010"

From dftwiki3
Jump to: navigation, search
(Question Group 1)
(More challenging pipes)
 
(21 intermediate revisions by the same user not shown)
Line 1: Line 1:
<center>
+
<!--center>
 
<font size="+2">Page under construction!</font>
 
<font size="+2">Page under construction!</font>
 
<br \>[[File:UnderConstruction.jpg|300px]]
 
<br \>[[File:UnderConstruction.jpg|300px]]
</center>
+
</center-->
  
 
You can work in pairs on this lab if you wish.  Otherwise work individually.
 
You can work in pairs on this lab if you wish.  Otherwise work individually.
Line 9: Line 9:
  
  
* Login to a Linux box around you using your CSC220a account.  
+
* Login to a Linux box around you using your CSC220a account.
 +
* edit the file .bashrc that should already be in your directory:
  
=Question Group 1=
+
  emacs -nw .bashrc
 +
 
 +
* add the following two lines at the end of the file:
 +
 
 +
 
 +
PS1='[\h]\n[\t] \w\$: '
 +
PS2='> '
 +
 
 +
* Save the file.
 +
* By default, the shell into which you start is the tcsh.  Switch to bash by typing the following command at the prompt:
 +
 
 +
  bash
 +
 
 +
* Verify that your prompt has changed and looks something like this:
 +
 
 +
[beowulf]
 +
[09:52:24] ~$:
 +
 
 +
* You are now ready to explore '''bash''' commands...
 +
 
 +
=Path-Related Questions=
  
 
;Question 1
 
;Question 1
Line 27: Line 48:
 
: You will notice that some user accounts still exist in '''home'''.  Which are they?
 
: You will notice that some user accounts still exist in '''home'''.  Which are they?
  
=Question Group 2=
+
=Questions about File-Searching=
 +
 
 +
: With Linux, the name of the printers supported are listed in a file called /etc/printcap.  Look at its contents.
 +
 
 +
 
 +
;Question 1
 +
: Figure out a way to get only the entries from this file that represent printers that are in Ford Hall.
 +
 
 +
='''Filter'''ing Log Files=
  
* With Linux, the name of the printers supported are listed in a file called /etc/printcap.   Look at its contents.
+
: Open a browser window and load up the following URL: http://maven.smith.edu/~hadoop/log.txt
* Figure out a way to get only the entries from this file that represent printers that are in Ford Hall.
 
  
=Question Group 3=
+
: Notice that it is a long log of the output of a research program I have been running recently.  It is very long and contains a lot of information: some useful, some not.
  
* Open a browser window and load up the following URL: http://maven.smith.edu/~hadoop/log.txt
+
: You are going to get a copy of this file into your account.  Instead of copying and pasting the text into a file, you are going to use a useful utility called '''wget'''.  '''Wget''' is a Linux utility that allows you to grab Web pages from Web sites, without using a browser.   
* Notice that it is a long log of the output of a research program I have been running recently.  It is very long and contains a lot of information: some useful, some not.
 
* You are going to get a copy of this file into your account.  Instead of copying and pasting the text into a file, you are going to use a useful utility called '''wget'''.  '''Wget''' is a Linux utility that allows you to grab Web pages from Web sites, without using a browser.   
 
  
 
:Try it:
 
:Try it:
Line 42: Line 68:
 
   wget http://maven.smith.edu/~hadoop/log.txt
 
   wget http://maven.smith.edu/~hadoop/log.txt
  
* Check that the file is in your directory
+
: Check that the file is in your directory
  
  
 
;Question 1
 
;Question 1
 
: How many lines of text does the file contain?
 
: How many lines of text does the file contain?
 +
  
 
;Question 2
 
;Question 2
Line 53: Line 80:
 
  real 23m6.777s
 
  real 23m6.777s
  
* Go ahead, list the real execution times.  What is the shortest time recorded?  The longest?
+
 
* List not only the real execution times, but also the lines of the form:
+
: Go ahead, list the real execution times.  What is the shortest time recorded?  The longest?
 +
 
 +
;Question 3
 +
: List not only the real execution times, '''but also the lines of the form''':
  
 
  processing noTasks = 17240  maxNoTasks = 8,  splitSize = 33554432L
 
  processing noTasks = 17240  maxNoTasks = 8,  splitSize = 33554432L
 +
 +
: The output should look something like this:
 +
 +
 +
processing noTasks = 862  maxNoTasks = 8  splitSize = 33554432L
 +
real 22m11.284s
 +
processing noTasks = 862  maxNoTasks = 16  splitSize = 33554432L
 +
real 0m13.113s
 +
processing noTasks = 1724  maxNoTasks = 8  splitSize = 33554432L
 +
real 0m10.891s
 +
processing noTasks = 1724  maxNoTasks = 16  splitSize = 33554432L
 +
real 0m40.891s
 +
processing noTasks = 80  maxNoTasks = 8  splitSize = 33554432L
 +
real 2m54.601s
 +
 +
=Pipes=
 +
 +
;Question 1
 +
: How many users have accounts on grendel (or beowulf)? (''Hints: use ls and wc and a pipe'')
 +
 +
 +
;Question 2
 +
: Who are the three users who have modified their account most recently? (''Hints: remember the -ltr switches for ls, and pipe the output to the appropriate command that will give you only three lines'')
 +
 +
 +
;Question 3
 +
: Same question, but the three who haven't modified (or touched) their account for the longest time?
 +
 +
 +
;Question 4
 +
:Who are the users who have modified their account today? (''Hints: today is a unique character pattern... "Sep  13" '')
 +
 +
=More challenging pipes=
 +
* Use emacs to create the following program in your 220a account: [[CSC220 StdoutStderr.py | stdouterr.py]]
 +
* Make your program executable
 +
 +
chmod +x stdouterr.py
 +
 +
* run your program
 +
 +
./stdouterr.py
 +
 +
:<font color="magenta">It was observed in the lab that the program might not work when executed as shown above.  There are several possibilities for this.  One could be that you are using a Windows machine, and when copying-pasting the text of the program in emacs, Windows uses carriage-return (Ascii code 13) to implement the end of lines, while Linux and Macs use line-feed (Ascii code 10) for that purpose.  One solution to replace Ascii 13 by Ascii 10 is to use the '''dos2unix''' utility, as follows:
 +
 +
  dos2unix stdouterr.py
 +
 +
:You can now try to run stdouterr.py as shown above. 
 +
 +
:If that still does not work, you can try the old-fashion way of running python programs:
 +
 +
  python stdouterr.py
 +
 +
:and that should work in most cases.  Good luck! </font>
 +
 +
 +
:observe the long output.  If you observe closely the listing, you will discover that some lines contain error codes, of the form
 +
 +
Error 404: blue screen alert!
 +
 +
;Question 1
 +
: run the program and filter its output so that you see only the lines containing error messages
 +
 +
 +
;Question 2 (tricky)
 +
: How many lines are output by the program?
 +
 +
 +
;Question 3 (trickier)
 +
: run the program and use commands that will display only the '''number''' of Error messages
 +
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
[[Category:CSC220]][[Category:Labs]][[Category:Bash]]

Latest revision as of 17:25, 17 November 2010


You can work in pairs on this lab if you wish. Otherwise work individually.

Login

  • Login to a Linux box around you using your CSC220a account.
  • edit the file .bashrc that should already be in your directory:
 emacs -nw .bashrc
  • add the following two lines at the end of the file:


PS1='[\h]\n[\t] \w\$: '
PS2='> '
  • Save the file.
  • By default, the shell into which you start is the tcsh. Switch to bash by typing the following command at the prompt:
 bash
  • Verify that your prompt has changed and looks something like this:
[beowulf]
[09:52:24] ~$:
  • You are now ready to explore bash commands...

Path-Related Questions

Question 1
What is the path of your account? In other words, what subdirectories does one have to traverse to reach your account.


Question 2
What other subdirectories are at the same height as yours in the directory tree?


You will notice that all user accounts are in a major directory called Users. The old standard for users on a linux system is to have the users in a directory called home in the root directory.


Question 3
You will notice that some user accounts still exist in home. Which are they?

Questions about File-Searching

With Linux, the name of the printers supported are listed in a file called /etc/printcap. Look at its contents.


Question 1
Figure out a way to get only the entries from this file that represent printers that are in Ford Hall.

Filtering Log Files

Open a browser window and load up the following URL: http://maven.smith.edu/~hadoop/log.txt
Notice that it is a long log of the output of a research program I have been running recently. It is very long and contains a lot of information: some useful, some not.
You are going to get a copy of this file into your account. Instead of copying and pasting the text into a file, you are going to use a useful utility called wget. Wget is a Linux utility that allows you to grab Web pages from Web sites, without using a browser.
Try it:
 wget http://maven.smith.edu/~hadoop/log.txt
Check that the file is in your directory


Question 1
How many lines of text does the file contain?


Question 2
The second question is to list only the lines that list the real execution time. These lines look like this:
real	23m6.777s


Go ahead, list the real execution times. What is the shortest time recorded? The longest?
Question 3
List not only the real execution times, but also the lines of the form:
processing noTasks = 17240  maxNoTasks = 8,  splitSize = 33554432L
The output should look something like this:


processing noTasks = 862  maxNoTasks = 8  splitSize = 33554432L
real	22m11.284s
processing noTasks = 862  maxNoTasks = 16  splitSize = 33554432L
real	0m13.113s
processing noTasks = 1724  maxNoTasks = 8  splitSize = 33554432L
real	0m10.891s
processing noTasks = 1724  maxNoTasks = 16  splitSize = 33554432L
real	0m40.891s
processing noTasks = 80  maxNoTasks = 8  splitSize = 33554432L
real	2m54.601s

Pipes

Question 1
How many users have accounts on grendel (or beowulf)? (Hints: use ls and wc and a pipe)


Question 2
Who are the three users who have modified their account most recently? (Hints: remember the -ltr switches for ls, and pipe the output to the appropriate command that will give you only three lines)


Question 3
Same question, but the three who haven't modified (or touched) their account for the longest time?


Question 4
Who are the users who have modified their account today? (Hints: today is a unique character pattern... "Sep 13" )

More challenging pipes

  • Use emacs to create the following program in your 220a account: stdouterr.py
  • Make your program executable
chmod +x stdouterr.py
  • run your program
./stdouterr.py
It was observed in the lab that the program might not work when executed as shown above. There are several possibilities for this. One could be that you are using a Windows machine, and when copying-pasting the text of the program in emacs, Windows uses carriage-return (Ascii code 13) to implement the end of lines, while Linux and Macs use line-feed (Ascii code 10) for that purpose. One solution to replace Ascii 13 by Ascii 10 is to use the dos2unix utility, as follows:
 dos2unix stdouterr.py
You can now try to run stdouterr.py as shown above.
If that still does not work, you can try the old-fashion way of running python programs:
 python stdouterr.py
and that should work in most cases. Good luck!


observe the long output. If you observe closely the listing, you will discover that some lines contain error codes, of the form
Error 404: blue screen alert!
Question 1
run the program and filter its output so that you see only the lines containing error messages


Question 2 (tricky)
How many lines are output by the program?


Question 3 (trickier)
run the program and use commands that will display only the number of Error messages