- Getting an Account:
If you don't already have an account on the
CS Dept Sun Ultra network, then get a user name and password from your
instructor.
- Finding a Machine: Locate an available Sun Ultra
computer, or
personal computer you can telnet from. Your instructor and/or a lab
assistant
can help you.
- Starting to Login: Some names of the lab Sun Ultra's
are:
altair, arcturus, barnard, capella, castor, centauri, ceti, deneb,
omicron,
polaris, pollux, regulus, rigel, saiph, sirius, sol, soleil, spica,
vega, and
zaurak. If you are telnetting in from a computer that is not a Sun
Ultra,
make a random choice and log in to one of the machines named above. If
you
need help logging in, raise your hand or consult the appropriate
section of
the handout entitled Gaining Access to Workstations in the Computer
Science
Department Network. (This document is available in the class web
space
under the file name
loginDirections.html
.)
- Entering Username and Password: To login, you enter
your user
name and password when prompted. The password you type will not show on
the
screen. This is normal. It is a security feature that helps prevent
others
from observing your password.
- Declaring a Terminal Type and Waiting for Login to
Complete:
If you are telnetting, then after you successfully log in, the system
may ask you about your terminal type. This means the system needs to
find out what kind of terminal control codes are being used. If you
are asked about this, just enter "vt100". Then wait for the
shell prompt to appear.
The shell prompt will probably be your user name, followed by an "@"
sign,
then the name of the host you are logged into, then a colon, and then a
few
more characters. For example, if your user name were "jdoe"
and you
were logged into zaurak, your shell prompt would be something like:
"jdoe@zaurak:(~)". This prompt means that the Unix shell
program is
ready to accept a command.
If you just sit down in front of one of the Sun Ultra's and try to
login to it
(it's called "logging in at a console"), you may see a panel asking
about
which graphical user interface (GUI) you want to use. If so, be sure
that Common Desktop Environment (CDE) is selected. Then wait
until the
graphic "desktop" appears. Next near the bottom of the screen, move the
mouse
arrow into the small square that is just to the left of the square
containing
the question mark (?). Then move to the little triangle at the top of
the
square and click on it. A menu titled "Hosts" should pop up. If that
doesn't
happen, raise your hand to get some help. Once you have the menu, click
on
"Console." The menu will retract, and a new window will appear with a
shell
prompt as described above.
- Changing Your Password:
Optional step: At this time, you can change your password. You just
click
somewhere in the middle of the window containing the shell prompt and
then
enter "nispasswd" After that, follow the directions on the
screen.
Before you enter the command, you must first think of a good password.
Check
out this
advice on choosing a password.
- Starting the Editor and Entering Text: Enter "jove
p1.cpp".
This starts up a text editor called JOVE, working with a file buffer
called
p1.cpp.
JOVE is a lot like some PC applications you may be familiar with:
Notepad,
TextEdit, or SimpleText.
Unless the file already exists, the screen goes blank, except for some
documentation lines at the bottom. JOVE is running. Type the following
text.
It is a very simple C++ source program. If there is already text on the
screen, erase it and type the text below.
#include <iostream>
using namespace std;
int main (void)
{
cout << "Hello World!" << endl ;
return 0 ;
}
- Saving and Exiting: Now figure out how to use the
keyboard to do this JOVE command:
C-x C-\
What I mean by the command above is "while holding down the ctrl-key
with one
hand, with the other hand press the x-key, release the x-key, press the
\-key,
and release the \-key. Finally release the ctrl-key."
Consult
JOVE -- a quick reference guide
for more information about JOVE commands:
If you haven't done it already go ahead now and do a C-x C-\
command in the window where JOVE is running.
The C-x C-\ command causes a copy of the program you typed to
be
saved. It is saved as a file named p1.cpp, because of the name you
typed in
step 7.
C++ programs for the g++ compiler on the Suns are supposed to
have
names ending in ".cpp" or ".cc". In other words, they should have names
like
p1.cpp, myprog.cc, prog3.cpp, and so on. This is very important. If the
".cc" or ".cpp" is missing, the compiler or linker may fail, even
though the
program has no errors.
Now do this JOVE command:
C-x C-c
(You have to use again the definition of C- you just learned.) The
command
causes JOVE to terminate. You should now be seeing your shell prompt
again.
- Compiling and Linking: Next enter "g++ p1.cpp".
This is
the command that compiles (and links) your program. It tells the
compiler
(g++) to translate p1.cpp into a machine-language version of
the
program.
- Checking for Errors and
Executing the Program: If you got an error message, it probably
means
that you made a mistake when you typed the program. In that case, fix
it: go
back to step #7. If there were no errors in your program, then your
compilation succeeded, and the name of the executable translation of
the
program is "a.out". In that case, enter "a.out", to
execute
the program. You should see the message "Hello World!" that
your
program prints on the screen. Did you see it? If so, give yourself a
pat on
the back. You just wrote a C++ program, and it does what it's supposed
to
do.
- Making a Record of a Program Run: Now that you are
sure the program is working correctly, let's
do another
test. This one will be "for the record." Enter "script p1.script"
and wait until the computer writes a prompt on the screen again. (There
may
be a slight delay. The prompt you get now may be different than
before.)
Here's an explanation of what you just did: The "script"
command
turns on a program that makes a record of whatever appears on the
screen. The
command you entered was "script p1.script" so the record the
script
program makes will be a file called p1.script.
Enter "a.out" and see your "Hello World!" message
written to
the screen again. Now enter "exit" to turn off the scripting
program. From the time you entered "script p1.script" to the
time
you entered "exit", all things that were written on the screen
were
also recorded in the file called p1.script.
Enter clear to clear the screen. Now enter "cat p1.script".
This causes the computer to type the contents of the script file you
made.
It should look something like this:
Script started on Sat Aug 21 19:05:11 2004
jdoe@vega:(~) a.out
Hello World!
jdoe@vega:(~) exit
script done on Sat Aug 21 19:17:37 2004
Note that the script file (named p1.script) starts and ends with
"timestamps"
that tell when the script was started, and when it was completed. In
between
it reproduces what you typed.
Now enter "jove p1.script" so you can look at the file with
the JOVE
editor. You see your script. You also see "weird" characters in the
script
like ^M at the end of each line, and maybe some other things. These
characters are an undesirable side-effect of the way the scripting
program
interacts with special characters that handle the terminal display. The
weird
characters are sometimes visible, and sometimes not, depending on just
how you
try to display your script file. The characters were not visible when
you
displayed p1.script with "cat," but they were visible when you
used
JOVE. Do a C-x C-c command to exit JOVE.
When you turn in a real programming
assignment, you will be sending me the
source code, plus a script similar to the one you just made. The script
will
be a record that will show me that you did the right kind of testing of
your
program.
I require you to run your script through a filter before you send it to
me.
It's a way to get rid of most of the weird characters, so the script
will be
more readable. It is easy to do, no matter how big the script is.
Here's how: Enter "cat p1.script | col -b
>
temp". This command pipes the script file to the input
of the
command "col -b > temp", which filters out some of the
weird
characters and writes the output to a file named temp. Now the temp
file is
the filtered version of the script. Enter "mv
temp p1.script" to replace the script file with the new
filtered version. Now enter "jove p1.script" again. See how
the
file has been cleaned up? Good. Exit JOVE again by doing a C-x C-c
command.
- E-Mailing Program and Script: When you have the shell
prompt
back, enter
mail -v -s "p1 source" mmartin@cs.csustan.edu < p1.cpp
DO include the quotes above! This command sends me an electronic mail
(e-
mail) message. (To get another prompt from the shell, you may need to
press the Enter key
now.)
Because you typed
-s "p1 source"
in the command above where you did, the subject line of the e-mail
message
that comes to me will be "p1 source". Because you typed
< p1.cpp
where you did in the command, the message I will receive will be your
file
called p1.cpp, which is your program.
Since I receive large volumes of e-mail it is very important
that you
put the right subject line on every e-mail you send to me.
As the course progresses, you will send me many e-mail messages.
Usually they
will be files that you have prepared previously. For example, a file
you send
may contain a C++ program, a script of the tests you made of a program,
or a
question about an assignment. You can send any of these things to me
using
a command that has the same basic form as this command:
mail -v -s "p1 source" mmartin@cs.csustan.edu < p1.cpp
Of course, you have to use different versions of the command, depending
on
what subject line you want and what file you want to send to me.
It is OK if the subject line is a series of several words like
"Come quickly, the printer is jammed!"
but the series of words must be quoted like the example above. Also,
the
(-s) has to come just before the quoted subject.
You don't have to include the flag (-v) in the command. If you
do
include it, put it where shown -- before the (-s).
When you
include the (-v) the program that transmits the mail responds
to you
using something called 'verbose mode'. The mail-transmission program
prints
important parts of a kind of dialogue that takes place between the
sending and
receiving programs as the mail is sent. If, near the end of that
dialogue,
you see on the screen a confirmation message like
"mmartin@cs.csustan.edu... Sent (i7M2dO7s007156 Message accepted
for delivery)"
then probably the mail you sent got through to my electronic mailbox.
If you
see an error message, you probably need to try to send the program
again. If
you are careful and type the mail-sending command correctly, there is
very
little that can go wrong. Even if the destination computer is down, the
sending computer will keep trying to send the e-mail ... for several
days if
necessary.
How can you be sure that I get the e-mail you send? Usually it is
enough to
do two things: First use the -v flag and verify that the output looks
'normal'. Second, wait a minute or so and then read your unix mail by
just
entering
mail
and look to see if there is a line at the bottom of the display with
subject
saying "Returned mail," and with timestamp close to 'now.'
If you see that, then enter the message number. For example if you see
something like:
>R 42 Mail Delivery Subs Sat Aug 21 20:49 71/2368 Returned mail: see transcript for details
?
at the bottom of your screen, enter 42 and read the message. It will be
a
message from the mail-sending program telling you it could not send
your
e-mail and trying to explain why. Read through the information. Press
the
space bar, if necessary, to get to the end of the message. Try to
figure out
what the error message means.
When you get the
?
prompt from the mail-reading program again you can enter an x to quit.
Try
sending the mail again ... this time correctly.
Now enter
mail -s "p1 test script" mmartin@cs.csustan.edu < p1.script
This sends me the script file you made. This time you left out the -v,
so
mail "does its work silently."
Congratulations! You have just completed all the steps of a sample
programming assignment.
- Change Your Password: If you haven't already done so,
think of a
good password now and change your password. See step 6 for the
directions. A
secure password is very important to you. Attempted break-in's are
common.
If someone gets access to your account and trashes the class work in
your
files then you have a problem! Also, someone could get control of your
account, masquerade as you, and do bad things.
- Exiting the System: If you are telnetting, make a safe
exit from
the system by entering "logout". If you are at a console, then
click
the right mouse button in the background, select "Logout", and click on
"OK".
- The End: You do good work! Go get a cup of coffee, or a
glass of
your favorite beverage, and kick back.