Lab 01

DUE DATE:    This lab must be completed by Saturday, 10:30am, September 15th. Note: After the first few labs, labs will be due on the Saturday of the week they are assigned. Because students sometimes enroll late, have account problems, etc., all the first 3 labs are due on the same date. You are encouraged to do them, one per week, and submit each as you complete it. Ask your TA to verify that your lab was submitted correctly, and get his/her help if need be before the deadline.

OBJECTIVE:

Become familiar with Unix/Linux commands.
When working on Unix and Linux machines, you use command line arguments to make directories, copy files, etc. In subsequent courses, you will be expected to be able to use these commands. This lab will give you practice working with the Linux file system..

GRADING

Total 10 points

PREPARATION:

If you are new to the GMU computing environment, please see
http://ite.gmu.edu/labs/newstudents.htm
and follow the directions there for activating your Mason and IT&E accounts.

BACKGROUND:

Review the commands at http://www.debianhelp.co.uk/commands.htm. If this is all new to you, also check out

ASSIGNMENT:

Part One: Changing your UNIX passwords
In this part you will login to your UNIX accounts and change your passwords. This assumes you already have a MASON/OSF1 account and an ITE account setup. If you do not, see http://ite.gmu.edu/labs/newstudents.htm.

Do note that the server mason.gmu.edu is the same machine as osf1.gmu.edu (it just has two names).

  1. To change your password boot your lab machine into Unix.
  2. Login to the machine using your account name and password (should be your mason e-mail account name and password)
  3. Open a command window
  4. You are now at a Unix command prompt. 
  5. The command "passwd" is used to change your password. At the command prompt type:  passwd
  6. This command will ask you to type in your current password and then a new password (twice)
  7. After doing this your account password should be changed.
  8. Make sure to REMEMBER your new password!!!
  9. As proof, email the TA from Unix. 
      1. At the command prompt type: mailx -s "lab section cs211-2xxx mason proof" YOUR_TA_Email@gmu.edu
        This mail command sets the subject to "lab section...." and lets you type in an email to send.
      2. Type in the body of the email:
        I have a ITE Unix account
        I have changed my password
        I will remember my password

        YOUR_FIRST_NAME YOUR_LAST_NAME
        .

        Make sure to type in the period as the last line. The period tells the computer you're done typing and sends the email. A full example:
         mail example
  10. Now we'll do the same thing from the mason.gmu.edu unix cluster
  11. Enter the command ssh mason.gmu.edu
  12. If prompted to accept an RSA key, type yes
  13. Now repeat the commands from step 4 above to change your password on mason. Make sure to change your email to: 
    I have a mason (osf1) Unix account
    I have changed my password
    I will remember my password

    YOUR_FIRST_NAME YOUR_LAST_NAME
    .
  14. Type exit to logout of mason and go back to zeus

Part Two: Practicing your Unix and Java skills
Setting up your Unix environment. Everytime you enter a command window in Unix the system runs a startup script. The startup script is dependant on which shell environment you are in. For the bash shell, the startup script is .bashrc . By default you don't have one, so lets add one to make your environment a little better.

Steps:
  1. Login to the Unix box
  2. Open a command window
  3. The wget command can be used to download a file or an entire website from a URL. We'll use to get a single file from the web:
    1. Enter the command: wget http://cs.gmu.edu/~dfleck/classes/cs211/fall07/labs/lab1/startup_script
  4. If successful you now have a file named startup_script in your home directory
  5. To test the file use the source command. This command runs a file as a script):
    source startup_script
  6. If successful your command prompt should have changed to include your username, host machine and current directory. This is a much more useful prompt to have.
  7. Now you must rename (move) the startup script to .bashrc (the file named ".bashrc" is automatically run when you login. This way, next time you login you will have the nicer prompt). Using the mv command you can move files.
    mv <source file> <target file>
    mv startup_script .bashrc
  8. Close your command prompt window and open a new one to verify the nicer prompt shows up. If it didn't are you sure you have a file name .bashrc in your home directory (type: ls -la to be sure. Note the file MUST start with a period .bashrc). 

  9. Almost there, now all we have to do is a Java program from the command line
  10. First, use the script command to record your actions on the command line.
    script yourname
    This will create a file called yourname with all the actions you perform on the command line.
  11. Using wget download the Jar (Java Archive) file from: http://cs.gmu.edu/~dfleck/classes/cs211/fall07/labs/lab1/hangman.jar
  12. Un-archive the file using the jar command (jar -xvf). 
    jar -xvf hangman.jar
    Jar is the Java file compression utility (very similar to zip on Windows.. but it works everywhere!). Option x = extract, option v = verbose, option f = extract from this file, so "-xvf hangman.jar" means to extract hangman.jar and be verbose (tell the user what's going on). Run the jar command with no options to display a message explaining all the options.
  13. You should now have a directory called hangman with source code files in it.
  14. You need to go into the hangman directory by issuing the change directory command:
    cd hangman
  15. In that directory there is a file named sourcecode.java, but this is NOT the correct name for the class. Using the grep command you can find the class defintion inside the file. Run the command:
    grep public sourcecode.java
    This will find any line in the file that has the word "class" in it. The correct name of the file is the class name you see on the line "public class xxxxxx".
  16. Rename the file to the correct class name (remember Unix is case sensitive!!!). If you don't remember how to rename a file, see step 7 above!
  17. Move to the parent directory by issuing the command cd .. (".." is a shortcut for the parent directory. "cd ../.." will go up two parent directories. 
  18. Compile the Java program by running the Java compiler:
    javac hangman/*java
    This will compile all the java file in the hangman directory.
  19. Lastly, run the java program by running:
    java hangman.xxxxx
    (replace the xxxxx with the correct class name and note the "period". The package name is "hangman" and the classname is "xxxxx")
  20. Stop the script recording by typing exit   . This stops recording your output to the script file "yourname".
  21. Upload this file using the WebCT "Assignments" page for Lab 1 and then press submit buttom. Remember, you if you only upload and do not submit your file the TA cannot grade your assignment. You can upload several times but submit only one.

    If you have any questions regarding how to submit assignments on WebCT, please address them to your TA or UPA during your lab session, by email, or during office hours.