Mcs 260, Fall 2010, Lowman

Quiz 1: First-MAC-Lab

Part I:

Use your icarus account from any computer connected to the internet. You can do this from Greece, the South Pole of even from home. You may need to first go to the ACCC webpage and activate your icarus account. It is assumed that you may not finish all of the lab procedure during the lab time. If you do not finish during lab time then you should finish the procedure in your own time.

Note

lines beginning with ">" indicate that you should enter the given command at the command prompt >.

0. Logon to a computer in the MAC-lab. Any files that you create/save on the lab computer will be deleted when you logoff. The first thing you need to do is to learn how to save your work so it is not lost. You should make it a habit to always create a new directory and keep all the files that you created in this directory. You can then archive the whole directory into a single file, compress the file (it is now a zipped tarball) , send the tarball to another machine or save it on a flash drive and finally extract the directory and all the files in it. You can then continue to work on your project on the new computer or transfer the tarball back to the lab machine on a later date to continue your work. You do not always need to create zipped tarballs, you can just transfer individual files. There are several ways to save your files from a lab computer.


  1. use web mail in the lab. Attach your tarball or file to an email and send it to yourself. You can then save and extract the files on your home computer.
  2. use sftp (secure ftp: file transfer protocol) to send it to another computer conected to the internet. You should consider this as a first choice when saving your files.
  3. save your files to your mounted Webdisk. You can mount your Webdisk while using a lab computer and transfer files to it while logged on. Files transfered to your webdisk will be saved for later use when you logoff.  As soon as you logon to the lab computer, click the icon on the desktop to mount your Webdisk.
  4. save your files to a flashdrive. It is common for users to forget to remove their flashdrive from the lab computer to find it is missing when they return for it. If you use a flashdrive, you should also use another method for saving your work.
  5. Another option is to only use the lab computer to connect to an other computer like icarus, raphael, your home computer etc. and just work on the remote computer. Your files are then saved on the remote computer. Use ssh to make a secure connection to a remote computer. In other pc-labs (not mac-lab) you can use a program named putty to connect to another computer. You can download putty for free to your home computer and use it to connect to your icarus account. You can then use icarus from home.
1. Open terminal window (click black icon) and connect to your icarus account. Both icarus and Macs use a unix operating system.:
> ssh icarus.uic.edu    --use the same netid and password you used to log
into the mac you are now using.
> pwd --unix command gives present working directory
> ls --lists files (ls -l includes file details)
> TERM=xterm --this changes the terminal type so you can use pine and pico. If you skip this step you may have problems.

On your icarus account open a bash shell. This will allow you to use the up/down arrows to recall commands you entered earlier.:

>bash   --later you will need to exit the shell before you exit icarus
>ls -l --note: lines beginning with "d" indicate a directory and "-" a file.

2. Make a directory mcs260 , cd into it , make a directory named firstlab and cd into it.:

>mkdir mcs260
>cd mcs260
>mkdir firstlab
>cd firstlab
Note, on unix you can enter more than one command on a line if seperated by a ";". Try it.

3. Type the python code to test the gcd algorithm. The algorithm will be explained later in a lecture.  Use the pico (or vim or emacs) text editor to create the following file named gcd.py:

> pico gcd.py

Now type the following python code, save it and exit pico. In Python, it is very  important that you get your indentation right. Some programmers claim that computer code is easiest to read if 4 spaces are used for each indention level.

# file: gcd.py
# your name, mcs260, Spring 2008
# an example of using python to implement the gcd algorithm

def gcd(m,n):
while n != 0 :
r = m % n
m = n
n = r
return m

def main():
print 'find gcd(m,n)'
m = input('enter m: ')
n = input('enter n: ')

print 'gcd(',m,n,') = ', gcd(m,n)

main()

Now run the program at the command prompt. If you get any error messages use pico to fix your typing errors and try again.:

> python gcd.py

Did the program give the correct answer?

4. Practice submitting your python program by sending it to yourself by using the pine email program and including gcd.py as an attached file. Open the received email, save the attached python program to a different directory ( use ~/tmp), cd into ~/tmp and run the program that you just sent to yourself.:

> cd ~    --on unix ''cd ~'' or just ''cd'' takes you back to your home directory.
''cd -'' takes you back to the directory that you just left (very useful). ''~''
can always be used as the path to your home directory.

> mkdir tmp
>cd tmp
> pine

Note, if you have problems using pine on your icarus account, then you can first use sftp to transfer the file to the pc-lab and then use webmail.

After starting the pine email program select COMPOSE to create and send an email to yourself with the file gcd.py attached. Try to figure out how to do this on your own. If you get stuck ask for help. Now exit pine and then start pine again. You have mail! Check your mail, save the attached file to ~/tmp directory, quit pine, cd into ~/tmp and run the python program that you just received. Try to do this on your own but ask for help if you need it. Later, i.e. not now, try doing this with the email program that you usually use.

If you want to remove the temporary file and directory then:

> cd ~/tmp
> pwd; ls --just to make sure you are in the right directory and the
file is there.
> rm gcd.py
> ls --o make sure it is deleted
> cd ..' --go back to the parent directory
> ls --just to make sure (always a good thing when deleting files and
directories)
> rmdir tmp -- you might not want to delete ~/tmp so you can use it again

Now exit icarus:

> exit    --to exit the bash shell you started earlier
> exit --to exit icarus and return to the lab operating system

Part II:

5. It is often more convenient to work on the Mac in the lab and save your work to either your icarus account or your mounted webdisk before logging off. Later in the semester, you will be using a machine named raphael instead of icarus. In your next session you can copy the files saved on icarus or webdisk back to the Mac and continue working on your projects. After logging on in the Mac-lab and mounting your Webdisk open a terminal window:

> cd; pwd    --to make sure you are in your home directory and see its path
> mkdir mcs260lab
> cd mcs260lab
> mkdir firstlab
> cd firstlab
> ls -- for fun

Use a text editor that is available on the mac and create the source file gcd.py. vim is a nice editor but you first need to learn how to use it. You can use Word but make sure you save your program as a text file and not a Word file. You might check if emacs is available. After you create your python program(s) you are ready to save the directory mcs260lab and everything in it to a single file. Either create a tarball "somename.tar" or a zipped tarball named "somename.tar.gz". The advantage of .tar is that you can open the file in a text editor and see what is in the file. The gzipped version is compressed and is a smaller file. As the directory grows this might become important.

  1. To tar the directory mcs260lab:

    > cd ~   --go home
    > ls --make sure you see the directory mcs260lab
    > tar cvzf mcs260lab_backup_15jan08.tar.gz mcs260lab
    > ls -l -- you should see your new zipped tarball

You can now save your tarball on icarus, your mounted Webdisk, a flashdrive (plug it in) or ftp it to your home computer. We will ftp (file transfer protocol) it to icarus. We will use sftp (a secure version of ftp) instead of ftp:

> sftp icarus.uic.edu     --or use yournetid@icarus.uic.edu
> ls -- shows files on icarus
> cd to the directory you want to save your file to or just save it to your
home dir.
> put mcs260lab_backup_27aug09.tar.gz
> ls --just to check
> bye --command to exit ftp and sftp
You are now back to the lab computer.

7. To see how this works logoff the lab computer you are using then logon again and mount your Webdisk (good habit but not using it now). Open a termial window and:

> cd ~  -- make sure you are home
> ls --the directory mcs260lab is probably missing. It was deleted when
you logged off. Not to worry!

Do not recreate the directory. Instead, use sftp to copy your tarred directory back to the mac and recreate the directory with everything in it by first unzipping it and then extracting the files from the tar archive:

> sftp icarus.uic.edu
> ls --see files on icarus
> cd into the directory where you saved your tarball
> ls -- make sure file is there
> get mcs260lab_backup_15jan08.tar.gz
> bye -- exit sftp

You are now back to the lab terminal:

> ls -l    --the .tar.gz file should be there
> tar xvzf mcs260lab_backup_15jan08.tar.gz
> ls --the directory mcs260lab should now exist
> cd mcs260lab
> ls -l

You can now pick up where you left off. Don't forget to save your new work. All will be deleted when you logoff the lab computer.

Part III:

8. Try saving your .tar.gz file to your mounted Webdisk (it must be mounted ). You can do this from the desktop or you can use a command window. Copy files to /Volumes/your_netid. This should make sense if you cd into /Volumes and list files. 9. Investigate to find out what software is available in the lab and what is useful to you. Also, you can save files to a flashdrive if you have one.

10. An alternate way to work with python in the Mac-lab is to find the applications menu and click MAC_Python. Now start the python ide IDLE. See you text for basic instructions on how to create and run python program. Try it.