UNIX: Level II

Server Support Group

Enterprise Information Technology Services

wsg@listserv.uga.edu

This on-line course was written by Alan Ferrenberg. He would welcome any comments you might have on this course.

This page has been accessed times since May 14, 1996.


Important Note

Please make sure that your WWW browser distinguishes between the back-tic character ` and the apostrophe character '. Without this distinction, several of the examples will not be correct!


Contents


Conventions

Typewriter font = commands
Italic typewriter font = arguments to commands
Bold typewriter font = response from computer
% = system prompt
ENTER = press the ENTER key
^u = hold the Ctrl key and type u


Getting Help


Workstation Support

EITS provides UNIX and workstation support to the UGA computing community through the Workstation Support Group. To contact WSG


Review: UNIX shells


Review: Shell variables


Review: Shell variable substitution


Review: Filename substitution


Review: Command substitution


Review: Input/Output redirection


Review: The UNIX filesystem


Processes and Commands


ps: Check on the status of processes


at: Run a command at a specified time


The cron subsystem


crontab File format


nice: Change the priority of a process


nohup: Protect a process from hangups


Other process-related commands

jobs
list your background jobs
kill pid
kill the specified process
kill %jobid
kill a background job
^z
suspend the current interactive job
bg
put a suspended job in the background
fg %jobid
bring a job to the foreground
batch
run a command when the system load permits. The syntax is similar to that of the at command.


Batch Queues


Advanced Commands


awk: A powerful file processing tool


awk programs

{
  x1 += $1
  x2 += $1*$1
}
END {
  x1 = x1/NR
  x2 = x2/NR
  sigma = sqrt(x2 - x1*x1)
  if (NR > 1) std_err = sigma/sqrt(NR - 1)
  print "Number of points = " NR
  print "Mean = " x1
  print "Standard Deviation = " sigma
  print "Standard Error = " std_err
}


cut: Write out selected parts of a line


diff: Compare files


find: Find files and manipulate them


grep: Match patterns in a file


ln: Link files


mkfifo: Create a named pipe


sort: Sorts and merges files


stty: Set/Change terminal settings


Program Compilation: cc and f77


make: Maintain programs


Sample Makefile

# Fortran compiler options
FFLAGS = -O3
# Object files needed for test.x
OBJS = main.o sub.o

# Link to get the executable file test.x

test.x: $(OBJS)
        f77 $(FFLAGS) $(OBJS) -o test.x

clean:
        rm -f $(OBJS) test.x


UNIX Shell scripts


Sample C shell (csh) script:

#!/bin/csh
#
# Check for all processes owned by the specified
# user ($1) on a set of machines
#
foreach comp ( sa sb sc sd se sf sg sh si sj sk )
  echo $comp
  rsh $comp ps aux | grep $1
  echo "  "
end


Same sample in Korn shell (ksh):

#!/bin/ksh
#
# Check for all processes owned by the specified
# user ($1) on a set of machines
#
for comp in sa sb sc sd se sf sg sh si sj sk
  do
    echo $comp
    rsh $comp ps aux | grep $1
    echo "  "
done


Shell script with awk

#!/bin/ksh
llq | tail +3 | awk '{
if (($2 != "") && ($2 != "jobs")) users[$2]++}
END {
  for (i in users) {
    printf("%8s  %d\n",i,users[i]);
    x += users[i];
  }
  print
  print "Total number of jobs = "  x
}' | sort +1nr


Sample Korn shell (ksh) script:

#!/bin/ksh
# Automatically submit 50 jobs when 3 or less in queue
i=1
while test $i -le 50
 do
  nj=`llq -u joe | tail +3 | wc | awk '{print $1-2}'`
  if test $nj -le 3
   then
     echo Submitted job number $i at `date`
     ugsub medium myprog.ksh $i
     i=`expr $i + 1`
   fi
  sleep 300
 done