CISC181 9am 2/18 (0.5) Debugging some messages that one student was seeing when logging in: Last login: Thu Feb 17 15:25:37 2005 from haydn.udel.edu Sun Microsystems Inc. SunOS 5.9 Generic May 2002 stty: Command not found. tty: Command not found. tset: Command not found. > First thing to know: when you first log in, there are some "script files" that are executed by the system to setup your shell. .cshrc .login .localenv The first thing I did to debug the problem was to see which shell the student is running Note: "jsample" is the username of the studnet, changed to protect his privacy... > > finger jsample finger: Command not found. > echo $PATH /opt/studio9/SUNWspro/man:/opt/man:/opt/SUNWspro/man:/usr/openwin/man:/usr/man:/opt/X11R5/man > Note that the finger command didn't work. This is because somehow the script files for setting up the acccount are probably messed up somehow, and so a few important directories are not in J. Samples' path. (Emacs side note: "M-q" "escape q" means is "reformat the paragraph".) The important directories missing are things such as /bin /usr/bin etc. These are where the most common unix utilities live, things such as ls, cp, mv, and indeed, finger. finger is a command that gives us information about a user. In particular, one of the things it gives us is "which shell the user is running". shell is a program that interprets the user input at the command line. Different shells have different features: sh is the original "Bourne shell" csh is the "C-shell"; an improvement on the Bourne shell that introduced C-like control structures (if, while, etc.) tcsh is a later version of the csh, which has command line editing for example, "hit the up arrow" to recall commands bash "Bourne again" shell is an improvement to the original Bourne shell that preserves the features of sh, but introduces nice things such as command line editing. You should use either tcsh or bash. I (Prof. Conrad) know tcsh better than bash, so that's what I recommend. I've recently become convinced that I should learn bash and switch to it. But I haven't yet. :-) Back to our student having problems... J. Sample can't even do the usual stuff: > ls ls: Command not found. > ls ls: Command not found. > emacs .cshrc emacs: Command not found. > more .cshrc more: Command not found. > All of this is becuase /bin and /usr/bin are not in that student's path. But if we try the following, it will work: > /bin/ls cisc181 mail nsmail public_html > (Emacs note: query-replace will let us change every occurance of a string to some other string.. for example change jsmith to jsample Run it with M-% (escape-%) > /bin/finger jsample Login name: jsample In real life: J Sample Directory: /home/usra/d0/55560 Shell: /bin/tcsh On since Feb 18 07:59:25 on pts/234 from roaming-212-152.nss.udel.edu Mail last read Fri Feb 18 03:31:12 2005 No Plan. Login name: jsample In real life: J Sample Directory: /home/usra/d0/55560 Shell: /bin/tcsh On since Feb 18 07:59:25 on pts/234 from roaming-212-152.nss.udel.edu > From this output we can see that our student is running the tcsh. Now let's figure out what's going on with these errors on logging in. First, we will fix the path interactively. The usual suspects are: /bin /usr/bin /usr/local/bin It turns out between those three we can find ls, more, cp, mv, finger, emacs, vi and most stuff we would need to fix a problem. The following shows how to list the current path, and then "prepend" /bin:/usr/bin:/usr/local/bin to our path. (Prepend means stick at the beginning, as opposed to "append" which is to stick at the end). > echo $PATH /opt/studio9/SUNWspro/man:/opt/man:/opt/SUNWspro/man:/usr/openwin/man:/usr/man:/opt/X11R5/man > setenv PATH /bin:/usr/bin:/usr/local/bin:$PATH > echo $PATH /bin:/usr/bin:/usr/local/bin:/opt/studio9/SUNWspro/man:/opt/man:/opt/SUNWspro/man:/usr/openwin/man:/usr/man:/opt/X11R5/man > Now we should be able to use commands such as ls, mv, cp, more, emacs, finger etc. to actually debug the problem. Now we will use ls to first see if J. Sample has a .cshrc and a .localenv file, and to see what the contents of .localenv are: > ls .cshrc .cshrc > ls .localenv .localenv > cat .localenv if -d /opt/sfw/bin then setenv NEWPATH /opt/sfw/bin:$NEWPATH setenv NEWPATH /opt/sfw/man:$MANPATH setenv LD_LIBRARY_PATH /opt/sfw/lib: $LD_LIBRARY_PATH endif if -d /opt/studio9/SUNWspro then setenv NEWPATH /opt/studio9/SUNWspro/bin:$NEWPATH setenv NEWPATH /opt/studio9/SUNWspro/man:$MANPATH setenv LD_LIBRARY_PATH /opt/studio9/SUNWspro/lib:$LD_LIBRARY_PATH endif> Two things we spot: a space in the LD_LIBRARY_PATH line in the first block of code, and no "new line" at the end of the second block of code, after the "endif" (note that the shell prompt ">" came right after the endif. Now, let's look at the .cshrc file. When you log on with csh or tcsh, the .cshrc file is the first one to be executed. If there is a .tcshrc, it plays a role somehow, but that's not an issue here: > ls .tcshrc .tcshrc: No such file or directory > So the contents of the .cshrc didn't turn out to be a problem. We fixed the .localenv file, and it didn't help; we still got: Last login: Fri Feb 18 07:59:25 2005 from roaming-212-125 Sun Microsystems Inc. SunOS 5.9 Generic May 2002 stty: Command not found. tty: Command not found. tset: Command not found. > So, now we look at one more file that gets executed when you first login, which is the .login file: > /bin/more .login # .login file ---- Commands for the start of login shells # # Read after the .cshrc file when you log in, and not read for # subsequent shells. For setting up terminal characteristics, ... etc... We find nothing wrong with the .login and .cshrc files. We are stuck. Then, finally, we notice what we should have noticed all along; one more error in the .localenv file: > cat .localenv if -d /opt/sfw/bin then setenv NEWPATH /opt/sfw/bin:$NEWPATH setenv NEWPATH /opt/sfw/man:$MANPATH setenv LD_LIBRARY_PATH /opt/sfw/lib:$LD_LIBRARY_PATH endif if -d /opt/studio9/SUNWspro then setenv NEWPATH /opt/studio9/SUNWspro/bin:$NEWPATH setenv NEWPATH /opt/studio9/SUNWspro/man:$MANPATH setenv LD_LIBRARY_PATH /opt/studio9/SUNWspro/lib:$LD_LIBRARY_PATH endif > The second line of each block of code says "NEWPATH" on the left hand side of the assignment statment, where is should say "MANPATH". "MANPATH" is used to set up the path where "man" looks for documentation (manual pages) for commands. So it should be: > cat .localenv if -d /opt/sfw/bin then setenv NEWPATH /opt/sfw/bin:$NEWPATH setenv MANPATH /opt/sfw/man:$MANPATH setenv LD_LIBRARY_PATH /opt/sfw/lib:$LD_LIBRARY_PATH endif if -d /opt/studio9/SUNWspro then setenv NEWPATH /opt/studio9/SUNWspro/bin:$NEWPATH setenv MANPATH /opt/studio9/SUNWspro/man:$MANPATH setenv LD_LIBRARY_PATH /opt/studio9/SUNWspro/lib:$LD_LIBRARY_PATH endif > We fix this, our student logs out and then back in again, and suddenly, everything works perfectly! (0) Go over HTML from lab02 (1) Review compling on strauss (went over on Fri 2/11, but make sure we covered everything in these notes... ">" means the Unix prompt Show how to compile this with just > CC lab01b.cc > ./a.out Show same result with just g++ and then running a.out > g++ lab01b.cc > ./a.out Show that we can rename to lab01b.cpp and it doesn't matter. > mv lab01b.cc lab01b.cpp > g++ lab01b.cpp > ./a.out Show that we can name the executable something else with the -o switch: > g++ lab01b.cpp -o lab01b > ./lab01b You need the . if "." is not in your path > ./lab01b You don't need the . if "." is in your path > lab01b How do we know if . is in the path? > echo $PATH How do we change our path (under csh or tcsh) ? What is csh or tcsh? emacs ~/.cshrc emacs ~/.localenv Using the "which" command to know where the compiler is coming from. (2) Convert sample program from 2/9 in "fictional language" into C++ integer w, x, y, z y = 0 w = 0 read x // value coming from user s/x/howMany/ while (y < x) // y < x is a boolean expression, true or false begin read z w = w + z y = y + 1 end print w // w is printed sum of all the z's s/w/sum/ end (3) Another program, demonstrating "while loop" and "if/else" http://udel.edu/~pconrad/cisc181/05S/lect/code/8am/02.16/min-max.cc Note that there is no prompt for input. Note that you can type all five numbers on the same line, or on 5 different lines, or mix and match. Note that if you type in 6 numbers, 6th one is ignored. What happens if you mix non-numerics in with the numerics? (4) Note to self... in the ACM lecture, Mike Riggio noted the importance of learning instrumentation for debugging, and use of a step-by-step debugger. So this is a reminder to me to cover that!