As always, don't forget how to learn about the commands described.
Connect and log into a sun
Use an ssh client to connect to sunlab.cse.lehigh.edu (which will randomly choose a sun for you). If desired, you could also ssh directly to a sun using its name such as antares, ganymede, metis, tethys, titania.
ssh, scp, sftp
As you know, ssh provides a secure mechanism to connect from one machine to another and start a shell. ssh also provides the foundation for a few other commands, such as scp and sftp, which you can think of as secure copy and secure ftp (file transfer protocol). The suns have each of these installed. You can run ssh at a shell to connect to another sun if you like, e.g.:tethys:~% ssh umbria
The authenticity of host 'umbria (128.180.120.82)' can't be established.
RSA key fingerprint is b1:c2:0d:16:d3:98:5b:7a:85:6a:60:15:52:82:59:03.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'umbria,128.180.120.82' (RSA) to the list of known hosts.
Password:
Last login: Thu Jan 25 10:46:16 2007 from tethys
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
LU CSE and ECE WorkStation Network
* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Department labs in PA112, PA118 and PA122 are closed *
* for construction. Most work will finish within the *
* first three weeks of the spring term. Remote access *
* via SSH works to many Suns. Notice will be posted *
* when the labs are open on their regular schedules. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Solaris 10 on SPARC: antares, ariel, europa, ganymede,
mars, mercury, metis, phobos, pluto, puck, sirius,
tethys, titania, triton, umbria
Solaris 8 on SPARC : proteus oberon
umbria:~%
So, the above demonstrates how I used ssh to connect from tethys to umbria and get a shell running there. Since I had not done so previously, ssh warned me that the secure fingerprint provided by umbria was not one that I had seen (and accepted before), and asks me to continue. It won't ask me that again (unless umbria's fingerprint were to change for some reason).
The scp and sftp allow you to securely copy one (scp) or more (sftp) files from one machine to another. Since I have two user accounts, I could use scp to copy files from one to another, such as:
tethys:~% scp brian@metis:cse271/dot-emacs dot-emacs Password: dot-emacs 100% |*****************************| 2559 00:00 tethys:~% ls -l dot-emacs -rw-r--r-- 1 bdd3 ugrad 2559 Jan 25 10:55 dot-emacs tethys:~%We can use sftp to allow us to connect and use ftp-like commands to get and put files to a remote host, such as some of the university machines to which you have access.
So here I used sftp to copy a file from my current account (dot-emacs) to my university afs space by connecting to an IBM workstation in Christmas-Saucon running linux. (You can find out where more such workstations are here.
tethys:~% sftp xs106a.cc.lehigh.edu Connecting to xs106a.cc.lehigh.edu... The authenticity of host 'xs106a.cc.lehigh.edu (128.180.52.11)' can't be established. RSA key fingerprint is 8e:46:5a:ce:c3:ee:c0:0e:7d:30:61:11:c9:c0:75:50. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'xs106a.cc.lehigh.edu,128.180.52.11' (RSA) to the list of known hosts. bdd3@xs106a.cc.lehigh.edu's password: sftp> put dot-emacs Uploading dot-emacs to /afs/cc.lehigh.edu/home/bdd3/dot-emacs sftp> ls . .. .Xauthority .bash_history .profile .ssh dot-emacs private public yesterday sftp> quit tethys:~%Changing your password
You were given an initial password to access your CSE account. For increased security, it is often a good idea to periodically change it. Your university account requires you to change it every six months, but the CSE accounts are not so strict. When you do want to change it, you'll use the passwd command, as in:
Note that it requires that you know your old password first, and will prevent you from re-using passwords that are too similar. The best passwords are often those that are abbreviations for something that is funny or offensive (to make it easy to remember).
tethys:~% passwd passwd: Changing password for bdd3 Enter existing login password: _ New Password: _ passwd: The first 8 characters of the old and new passwords must differ by at least 4 positions. Please try again New Password: _ Re-enter new Password: _ passwd: password successfully changed for bdd3 tethys:~%Disk usage and quota
As you continue to use your CSE account for multiple classes and perhaps email and web pages, too, you will be using more and more storage. A new user's storage allocation is small, but you can request additional storage easily if needed (email to help).
There are two UNIX commands that can help you understand how much disk space you are using. The first is du, which stands for disk usage. By default it tells you how many blocks of disk you are using in the current directory and within any subdirectories. A block in Solaris is 512 bytes, but the -h option will convert it to something more useful. Try it out on your account and see how much storage you are currently using.
The second command is quota -v. It shows how much total storage you have used on the filesystem and what your quota is.
So from this I can see that I am using 20MB in my home directory and my limit is 50 megabytes. The hard limit of 75MB allows me to temporarily (for a few days) use more than the 50MB if needed. If I try to create files that sum to more than 75MB, they will fail. See what your quota is.
tethys:~% quota -v Disk quotas for bdd3 (uid 43430): Filesystem usage quota limit timeleft files quota limit timeleft /home/jhw204 0 50000 75000 0 0 0 /home/bdd3 20611 50000 75000 1518 0 0 tethys:~%The grep command
Sometimes it is useful to find the lines of a file that match some pattern. A very simple use is to find the lines in a program that call a function. grep is a great command to use for this. For example, I can find every line that contains the string "print" in mycat.c:
I could equivalently have typed grep print < mycat.c. When used this way, we can think of grep as a filter. It is reading from standard input and filtering the content in some way and sending the remaining text to standard output.
tethys:~% cd mycat/ tethys:~/mycat% grep print mycat.c printf("We need an argument.\n"); printf("File is not found.\n"); /* print content to the screen */ printf("Output failure.\n"); tethys:~/mycat%Writing a filter
For the last task of the morning, let's write our own very simple filter. This program will be somewhat similar to our mycat program. Your task is to write a simple character filter to collapse extra white space in text files. The filter should change each tab character ('\t') to a space and collapse a series of two or more spaces into a single space. As a Unix filter, it should read its input from stdin and write its output to stdout. Do not use character arrays or strings for this program.
As an example usage using input redirection, assume the contents of the sample input file are as shown.
and once you have successfully written your collapse.c program, you can compile and run it as:
...% cat infile Where the Lehigh's rocky rapids Rush from out the West, Mid a grove of spreading chestnuts Walls in ivy dressed. On the breast of old South Mountain Reared against the sky, Stands our noble Alma Mater, Stands our dear Lehigh.
...% gcc -o collapse collapse.c ...% collapse < infile Where the Lehigh's rocky rapids Rush from out the West, Mid a grove of spreading chestnuts Walls in ivy dressed. On the breast of old South Mountain Reared against the sky, Stands our noble Alma Mater, Stands our dear Lehigh.