Comparing UNIX environments - Santa Monica College
  differences between kernels
  differences between shells
  differences between applications
Though the most fundamental operating system in computer science, development of UNIX over its 40 years has split and branched into a thousand variations. The original AT&T code base led to several commercial flavors like HP/UX (Hewlett-Packard), AIX (IBM), and Solaris (Sun Microsystems, now Oracle). Others resulted from the very major additions to the code base by the University of California at Berkeley. Berkeley's contributions live on in non-commercial versions also, like FreeBSD, OpenBSD, NetBSD. And upstart linux arose from a fresh effort starting in 1991 that very successfully mimicked the outward behavior of a UNIX environment and its components, but without a shared codebase. Linux (which is unitary) was then delivered in many "distributions" (which are not). They include slackware, gentoo, ubuntu, fedora, debian, and many others. Not to mention academic and experimental relatives like minix and the GNU operating system.
The similarities among "unices" outweigh the differences, much as with the dialects of a natural language like English. But those differences can be enough to get in the way. If you are familiar with one UNIX you are largely familiar with them all. But this exercise focuses on what may be unfamiliar. It sets 3 unices side by side to let us find where some of the differences lie. Broadly, between two platforms there can be diffences of operating systems (kernels) themselves, between shells (your points of contact with everything), and/or between particular applications. When you experience some unfamiliar behavior when visiting a UNIX foreign to yours, try to attribute it correctly. You're running FreeBSD. You ask to delete more lines of a document in vi than actually exist, expecting deletion to end-of-document, and nothing happens. Don't "blame" FreeBSD. It's probably an older vi, and its vi's "fault," not FreeBSD's.
It is assumed here you already have a DETER account and password, created following these instructions. Please log in to DETER and "Begin an Experiment," naming it "comparativeUNIX-xxx" (where xxx is some suffix like your initials likely to be unique to avoid name conflict with other students' experiments) and loading in this network specification (.ns) file (the file is inside a zip file, unzip after downloading).
Swap your new experiment in.
To interact with your nodes you need to gain an interface to each. You gain a terminal window interface to any of the nodes by "double ssh," connecting to users.isi.deterlab.net and from there to the node. For example, to connect to node FreeBSD:
ssh ‹your account name›@users.isi.deterlab.net
ssh FreeBSD.comparativeUNIX.SMC-CS41.isi.deterlab.net
(Important: This documentation is written as if the experiment name is "comparativeUNIX". The real name of your experiment being the variation comparativeUNIX-xxx, you should substitute the real name for your particular experiment wherever you see this document using "comparativeUNIX".)
Set up your monitor screen to contain 3 terminal windows, one to each of the experiment nodes arranged as in the graphic below. To do so first use ssh to get 3 terminal window connections to users.isi.deterlab.net, then from them again to the 3 nodes respectively as above. Your screen will look something like the following, with the windows stacked in the same order, and the title bars accessibly arranged for single-click selection of the window of any desired node. You are logged in on each machine under your own, non-root user account.
(As a possible alternative, there is a utility called "screen" installed on users.isi.deterlab.net. It is a character-mode program allowing you to open mulitple remote sessions and show them alternately or in split-screen.)
man uname | head
uname -s
Two Linux and one FreeBSD. We already knew that. So CentOS and ubuntu run the same OS. No they don't! On all the platforms, query the release and version levels for more detail:
uname -r
uname -v
cat /etc/issue
Anything useful? Any differences in behavior? Is FreeBSD a distribution or an operating system?We have to contend with different operating systems, different distributions, what about the shells? Those too. Most shells (not necessarily all!) maintain a variable named SHELL that contains the answer. Identifying our distribution or OS does not identify our shell; they're independent. There are serveral ways to try to identify the shell. On the 3 platforms:
ps ax | grep $$
in order to find the entry in the running process list for our running shell. We will locate it in the list by its process number ($$ gives us that). All 3 show tcsh (the c shell). Reinforce that observation, by running on all 3:grep $(whoami) /etc/passwd
and observing the last field in the user record. It holds the shell file to run whenever you successfully log in. If you are running tcsh, this is why. Yes, all 3 passwd files show tcsh to be your login shell. Now become root, on all 3 nodes:sudo su -
and again test on all 3 nodes what shell you are running, and what shell you are supposed to be running:
ps ax | grep $$
grep $(whoami) /etc/passwd
/bin/bash --version
for CentOS and ubuntu or:/bin/csh --version
for FreeBSD. FreeBSD is running csh for root, same as it was for your pre-su non-root account, while both linuxes run bash following su (what about the csh's they were running before, did those terminate?). Both linuxes are running the same shell, bash, but not really exactly the same because they are different versions. Which is the more recent? A shell is just a shell. That is, merely some particular program running under the supporting local operating system like any other program. And there are different shells out there, we're looking at two. We know that both tsch and bash are present on both CentOS and ubuntu, we saw both running. As well, a copy of bash is present on FreeBSD. If you wanted you could run it and operate in bash instead of tcsh. To view both shells sitting on each computer, on all 3:which bash tcsh
And there are some other shells installed on these boxes, and still more that could be obtained and installed. What is the import of having one shell versus another? Behavior! They are more similar than different but are different. Variable creation and assignment offers one example. Try this on both CentOS (where bash is currently running) and FreeBSD (where it's tcsh):
set y=5; echo $y
x=6; echo $x
These are differences among shells. Can we see any differences among the operating systems themselves? Each operating system knows (learns at boot) something about the hardware on which it's running. Usually there's a way to query it about that. But how the information is stored and queried differ. If you want to know about the cpu on one of the linux nodes:
cat /proc/cpuinfo
but on the FreeBSD node:sysctl hw.model
At the application level, there will be differences between one and another copy of the same program, such as the vi editor. Create a 20-line text file for vi on each platform:seq 1 20 | sed 's/^/This is line number /g' | tee testfile
Oops, didn't work on FreeBSD. There, try jot instead of seq:jot 20 1 | sed 's/^/This is line number /g' | tee testfile
Now on each node open "testfile" in vivi testfile
and within vi try to delete all of its 20 lines, in 2 stages. First on CentOS, once the file is open and the cursor on line 1, press 5 then dd in rapid succession. It means "delete 5 lines." Now 15 remain. Get rid of them by pressing 99 and dd in rapid succession. It means "delete 99 lines" and will erase the 15 lines it still has. Try the same in FreeBSD. What' happens (or doesn't) differently? This is a vi-versus-vi difference. What are these vi's? On CentOS and ubuntu:vi --version
On FreeBSD, open vi (on any or no file) and give a last-line command within it by typing : (colon) then, at the last line prompt, "version" and press enter. (Leave vi, colon-q-exclamation). Following is a further sampling of various differences.
echo one two three | gawk '{print $2}'
echo one two three | awk '{print $2}'
route -n
if you find it doesn't work then try:netstat -rn
updatedb: This command builds a database for later consumption by the locate command. The database contains a snapshot listing of all the files in the filesystem, when updatedb runs. Try it on all 3:updatedb
if you find it doesn't work then try:/usr/libexec/locate.updatedb
ifconfig: Look at the differences in this command's output. Run on all 3:ifconfig
The format differs. If you wrote a shell script to obtain an IP address from this output, by extracting it from the second line of output for an interface, it would work in linux but break in FreeBSD. Note also the NIC nomenclature differs, eth versus em. And, in linux you only see the interfaces that are "up," while FreeBSD's ifconfig shows you all interfaces regardless.
log file: The main log file, used for log message placement by many programs, is /var/log/messages. A program to write arbitrary text into the log is logger. On all 3 try:
logger "This is a test"
tail /var/log/messages
logger "This is a test"
tail /var/log/syslog
echo "Press enter to learn what the moon is made of"; read; echo "Green cheese"
tcsh's read built-in demands at least one argument. So give it a throw-away argument x:echo "Press enter to learn what the moon is made of"; read x; echo "Green cheese"
What about read's status as a shell builtin or a freestanding external executable? Look for an executable:which read
There's no executable in CentOS or ubuntu, so it must be a builtin. There is one in FreeBSD however find the commentary about that in the man page:man builtin | less
and look at the executable's source code:cat /usr/bin/read
Executable or builtin, what's the verdict?
echo echo is famously a command whose development got out of hand, in terms of being taken in different directions by different programmers resulting in incompatible versions (a nightmare for script programmers, who prefer to use printf for that reason). One feature you may or may not have is the ability for echo to ouput control characters, like tab:echo -e "One\tTwo\tThree\nFour\tFive\tSix"
What about echo's status as a shell builtin or a freestanding external executable? Look for an executable:which echo
Executable or builtin?
Answer the following questions and submit per your instructor:
1. You found differences in the way variables must be assigned.