CogSci 3 Assignment 3c-- Unix
Due Saturday, October 24th, 2009 at 11:59PM

Goals

Taking a very high level look at this assignment, the main goal is to publish your previous XHTML assignment on the world wide web. To do that, you will need to copy your XHTML page(s) to the webserver, and then change and verify the file permissions on your pages so they can appear on the web. The webserver for the class runs the UNIX operating system, which is where learning UNIX comes in.

The lower level goals are something like this:

  1. Use a secure shell, SSH, to access the course UNIX server (a computer running the UNIX or Linux operating system).
  2. Learn a little about a Command Line Interface (CLI)
  3. Use some basic UNIX navigation commands
  4. Experiment with refering to files in different folders.
  5. Learn the special notation for the parent directory: "..", and login directory "~".
  6. Create some directories for your future assignments
  7. Create your web directory -- public_html
  8. Copy your existing web page(s) and CSS sheets to your web directory
  9. Change file and folder permissions to allow the web server software access to your work.

Your assignment will be graded by looking at the files and directories you "create". Frankly, it's possible to cheat by using the GUI on a Windows or Macintosh computer on campus to do most of the assignment. So we are going to have you create a "session log" of your work, and will use that to verify that you used the UNIX CLI to do it.

As usual, these instructions assume that you are working in the class lab (or other ACS lab) on campus. It is certainly possible to do it from home, assuming you have an internet connection. If you have Windows, you will need both PuTTY (see below) to do the assignment and, to turn in the session log, FileZilla -- see the "turning in" documentation. If you have a Macintosh, you can use the Terminal (Applications->Utilities->Terminal) program. Unfortunately, there is no built in session loggin in Terminal, but you can use the UNIX command script to do the same thing. There will be a brief discussion on script in a minute.

Command Summary

There is a very large number of commands in UNIX. To accomplish this assignment, though, you will only need to know a few of them. Here is a table with the commands that you will need, plus a couple that you might need if you get introuble.

Syntax
Example -- Explanation
date
date -- prints the current date and time
pwd
pwd -- prints the absolute pathname of the current directory
cd [directory]
cd hw4 -- changes the current directory to the argument. If no argument is given, changes to your home directory
mkdir new_directory_name [other_new_directory_names]
mkdir hw9 -- creates a new directory with the name of the argument. If more that one directory name is given as an argument, it creates multiple directories
ls [file_or_directory]
ls hw4 -- prints an "icon" view of a directory (if a directory argument is used), or the current directory if no argument is given. If a file name is used as an argument, ls will print the name of that file (if it exists). This is actually a good way to test a pathname to see if it is valid, or to see if the file exists.
ls -l [file_or_directory]
ls -l hw4 -- if no argument (other than the -l flag) is given, prints a "details" view of the current directory. If a directory name is given as the argument, ls prints a "details" view of the contents of that directory. If the argument is a file name, then ls prints the details for just that file
ls -ld [directory]
ls -ld -- if no argument is given, ls prints the "details" for the current directory (rather than the contents of the directory). Similarly, if a directory name is given, then ls prints the details of the directory itself, rather than the contents of the directory
cp old_file new_file
cp hw4/index.html hw9 -- creates a copy of the first argument. If the second argument is a file name that doesn't exist, cp creates a copy of the first argument and gives it the name of the second. If the second argument is a directory name, then cp copies the file specified by the first argument in the that directory (second argument) and keeps the same name (first arugment)
mv old_name new_name
mv hw7 webdiretory -- renames the first argument (file or directory) to that of the second argument. As a special case, if the first argument is a file, and the second argument is a directory, the file is moved from its current location and put into the directory (second argument) and keeps the same name
chmod mode file_or_directory [other_file_or_directory]
chmod o+r index.html -- changes the permissions (mode) of its file or directory arguments
rmdir directory_name [other_directory_name]
rmdir booboo -- removes an empty directory. You shouldn't need this! Use with care. Much better would be to use mv to rename the erroneous directory bad1 or something
rm [file_or_directory] [other_file_or_directory]
rm bad_file -- removes a file. You shouldn't need this!

Notes:

icogsci1.ucsd.edu, the class server

The class webserver is the same icogsci1.ucsd.edu server that you have been using to turn in your assignments all quarter. To access the server for this assignment, however, you are going to log in using telnet. Telnet gives you a command line interface (CLI) or "Shell" access to the class server. The program that you type your commands into, and which runs them for you, is called the Shell.

Instead of the obsolete and insecure telnet program, you should use a version of SSH, "Secure Shell". In the class lab(s), ACS has 2 different programs: one called SSH, and other one is called PuTTY. PuTTY is free and can be downloaded to your home (Windows) computer if you wish to do the assignment from home. The instructions will concentrate somewhat on PuTTY because we think that's what most of you will be using.

Macintosh users who want to do the assignment at home, be patient.

Installing PuTTY

PuTTY is already installed on the class lab Computers. However, in Fall 2007, PuTTY seems to have disappeared from the Start menu. It is on the lab machines, however, and here's how to get at it.

Windows users working at home can download and use PuTTY from http://www.chiark.greenend.org.uk/~sgtatham/putty/

Using PuTTY

configuring PuTTY

Note, if you type in a "Saved Sessions" name (like icogsci1) and click the Save button, then PuTTY will save the the settings you have made and it will appear in the configuration dialog like the one pictured above.

While PuTTY is active, you can get back to the configuration menu (for instance, to change keyboard settings or the colors used) at any time by clicking on the icon to the left of "PuTTY" on the title bar, and then selecting "Change settings...". Make your changes, click on Session at the top left and you can save your updates.

Using SSH

The class lab(s) have SSH (called "secure shell"), which is located in Start->Programs->Secure Shell. Note there is also, a "Secure Transfer Client" in that same folder; you don't want that, but the "Secure Shell Client" instead.

Once SSH is running, you will see a window like the one below (click on it to see a larger image.)

Simply type Return to get the "Connect" dialog:

Enter the class server computer name, icogsci1.ucsd.edu, as the "Host Name" and your cg3fzz account code (not your ACS username!); and when prompted (a separate dialog), the corresponding password.

Macintosh Users

Mac OSX comes with a version of SSH. To use it, you must first open the Terminal application, which can be found in Applications->Utilities->Terminal. When you start Terminal, it will actually give you a UNIX window on your Macintosh! Then you type:
ssh -l cg3fzz icogsci1.ucsd.edu
where, of course, you use your class account instead of cg3fzz.

Security Alert!

Regardless of which SSH program you are using, the first time you try to connect to icogsci1.ucsd.edu you will most likely see a warning to the effect that icogsci1.ucsd.edu is "untrusted" and do you want to continue to connect. Like the one from PuTTY shown below.

This is perfectly normal, and only happens the very first time you connect to a particular host. In the case of PuTTY, you are offered 3 choices: Canceling will abort the connection attempt (and you'll have to start over), click "yes" will allow the connection and prevent the alert in future connections, while "no" will allow the connection but give you the alert the next time you connect. Presumably, you will select "yes".

Note to Macintosh users: the warning you see will not be a separate dialog window, just text in your SSH windown; to respond, you will have to type the whole word "yes"!

Logged in, Finally

When you have successfully typed your account and password, and dealt with the security alert, you will see a "message of the day" screen (or screens) like below (click on it to enlarge it). This message is a list of announcements from ACS about your account and use of the ACS labs. As the prompt at the bottom of the screen will suggest, type 'q' to get rid of the announcements.

Now, you should arrive at the shell prompt, in this case: "bash-2.05b$ "

Congratulations, you have successfully logged into a UNIX system!

Starting a session Log

As stated earlier, you need to create a transcript of your commands as you work through the assignment. Don't be concerned about the transcript containing mistakes and errors (typos, incorrect command usage, etc.). We expect that. We just want to verify that you actually did the assignment using UNIX tools instead of some other method.

Depending how which SSH you are using, there are different methods of starting the session log. We start with PuTTY.

Important!!! always make sure to append to your log file, rather than overwritting it! That will let you stop the assignment and start it up again later. If you overwrite, the session log will only contain the last bit that you did!

Logging your UNIX session using PuTTY

  1. Click on the icon on the left of the PuTTY title bar and select "Change settings..."
  2. Click Log all session data
  3. Give your session log a name and Browse to a folder to save it in; the desktop should be fine
  4. Click Apply.

When you are finished with the assignment, don't forget to transfer the log to your homework directory in your account.

Logging your UNIX session using SSH (in the class lab)

To start session logging using the SSH program in the ACS labs is simple. Just select File->Session Logging. The log file name should be called something like: session.log, and navigate to where you want to save the log file, on your desktop (or perhaps on the class server, since you can use the "Class Resources").

Again, when you are finished with the assignment, don't forget to transfer the log to your homework directory in your account.

Starting a session file ... the UNIX "script" command

If you are using a Macintosh, or a version of SSH other than the ones we described previously, you can use the UNIX script command to do your session logging. This is a little trickier than using the logging built into PuTTY or SSH (and only needs to be used if you are not using one of them). You should use it exactly as shown below:

bash-2.05b$ script -a cg3fxx.log
    
where cg3fxx.log is the name of the logfile and the -a flag tells the script to append to the file if it already exists, rather than save over it. After you execute this command, everything you type, and all of standard output will be recorded in this file, until you execute the exit command.

A demo session using script

Because script is a less obvious to use than the PuTTY session log, we've included a brief demo.

Notice in the above demo, that the cg3fxx.log file appears as one of the files in the directory when the ls command is issued.

The Assignment

If you haven't already done so, start your session log.

Typing Errors

If you make an error while typing a command, you can correct it before you type the Return key by typing the delete key (backspace or <- above the Enter key on a PC). If you wish to erase the whole line, Ctrl+U (Control Key + "U") will usually do it for you. (In UNIX, Ctrl+U is written as ^U.)

Try typing: asdfasdf and then erasing it with the Backspace key.

If, instead of erasing the letters, you see ^H or ^? appear, you need to change what character your SSH is sending when you type the backspace key. For instance, in PuTTY, you click on the icon on the left of the title bar and select "Change settings"; then click on Keyboard (under Terminal) and make your change; then select Session and save your change. (On the Macintosh, you would need to change the "Window Settings..." of you Terminal program.)

Task 1 -- Time stamp your assignment

Use the date program to time and date stamp your work. If you stop, and then restart your work (make sure to append to your log file!)

-bash-2.05b$ date
Sun Nov  4 21:41:48 PST 2007
-bash-2.05b$ 

Task 2 -- create the directories for the rest of your homeworks

You should be in your home directory at this point, right? Use the ls -l command to "see" what is there. You should see the directories (folders) from previous assignments. (There maybe other files and folders there, don't worry about them.)

You should already have hw3 directory created from the earlier parts of this assignment. If you do not have it, then use mkdir to create it now.

Then use mkdir to create the directories for the rest of the assignments: hw4, hw5, hw6, hw7, and hw8.

You should probably use the ls or ls -l to verify your results.

Task 3 -- change your prompt into something more useful

The prompt is a special Shell variable, called PS1 (prompt string 1). Here we will change the default prompt -bash-2.05b$ into something a little more useful for this assignment. The changed prompt will show the present working directory, so at any given time you now where you are (you can also get this information by using the pwd command). You can use the following syntax to do this (remember all commands in UNIX are case-sensitive).

-bash-2.05b$ PS1='[\u]\w > '
After you've executed the above command, your prompt should have changed into this:
[cg3f]~ >
Notice the prompt is immediately changed. What we just did is assign a different value to PS1. The characters \u and \w are special "escape" characters, which the system understands and translates to something meaningful. For example, \u corresponds to the current (u)ser (so you know who you are!) and \w corresponds to the present (w)orking directory. This is an abbreviated version of what pwd outputs, where the ~ corresponds to the path of your home directory, i.e. /home/linux/cogsci/cg3f/cg3fZZ/. Since most of the time you will be working under your home directory, the path of your home directory is replaced for economy of space.

Task 4 -- change the name of hw5 to public_html

Use the mv program to change the name of the hw5 directory to public_html

You should probably use the ls or ls -l to verify your results.

Why the name: public_html? Because on this webserver, a directory called public_html in a person's home directory is their personal web directory!

Task 5 -- copy your XHTML css assignment

Copy both your previous XHTML-css assignment and the css style sheet into your public_html directory. You will need to use the cp program to do this. But exactly how is up to you. We are being deliberately vague here. This is really the guts of the assignment -- how you refer to files in different directories. If confused, be sure to come to lecture as much will be revealed. smiley

**Update 04/22/2009**

Complete the following steps if the flower image not displaying correctly. First, copy the flower image from the hw2 folder to the public_html folder. Secondly, change the hw2 flower image URL (within the html file from part A) from ""../hw2/mask-cg3fyy.jpg" to "mask-cg3fyy.jpg".

Change the name to index.html

When you copy the XHTML assignment into your public directory (public_html) rename the html assignment to: index.html. You can either do this when you do the cp or in a separate step using mv. The style sheet should keep it's same name.

Why index.html? It's the default name for the main page in a web folder.

Task 6 -- change file permissions

Use the chmod command with mode "o+r" to change the permissions for all .html documents, your CSS sheet, and any images in your public_html folder, and don't forget the ones in your subfolders.

You'll want to verify all your .html files, CSS style sheet, and any images have been changed to mode 'o+r', like index.html below. (The example assumes you are in your public_html folder.)

[cg3f]~ > ls -l index.html
total 2
-rw-r--r--   1 cg3fzz   cg3f     204 Apr 27 14:26 index.html
[cg3f]~ >

Task 7 -- change directory permissions

As well as changing the permissions on your web files, you need to change the permissions on all directories that contain web files. Instead of "o+r", however, you will need to chmod o+x for your directories. Yes, directories plural. As well as the obvious public_html, you also need to make your home directory "o+x".

Hint: remember you can use ~ (tilde) to refer to your home directory, if it helps.

Then you can use "ls -ld" to verify that directory permissions look like the ones below, particularly the 'x' permission in the "other" portion of the permissions (the example assumes you are in your home directory).

[cg3f]~ > ls -ld . public_html
drwxrwx--x  4 cg3fzz        512 Apr 27 12:26 .
drwxr-x--x  2 cg3fzz        512 Apr 27 12:26 public_html
[cg3f]~ >

The final test

If you've done things correctly, your page is now on the world wide web! The URL is:

http://icogsci1.ucsd.edu/~cg3fzz
(with your account code, of course, and that's a tilde (~) in front of the cg3). If you will recall, the notation ~cg3fzz means the home directory of cg3fzz when used in UNIX commands. When it is used in a URL, it means the personal web directory for user cg3fzz. And in our case that means the subdirectory public_html in user cg3fzz's home directory.

Load that URL into a web browser and you should see your XHTML-css assignment! You should also see the color changes that your CSS style sheet creates. Remember that "Forbidden" means permissions issues which you need to fix.

If your page loads, but doesn't show the affects of your style sheet, make sure that the style sheet is in your web directory, and is "o+r". If that appears to be okay, make sure that CSS sheet name in the directory and the name in the <link> element in your index.html match exactly. If the names don't match, use mv to make the file name match what's in the <link> element.

If you make any changes (to permissions or filenames), reload your webpage.

Finish Logging

Once you are satisfied with your results, it's time to turn in your session log.

Grading

We will grade you on

©opyright 2006 Mary ET Boyle, and Mark Wallen
Last updated: Sunday, November 5, 2006
Massive updates: November 2007, mrw