Shellscript Interpreting


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Shellscript Interpreting
# 1  
Old 01-18-2002
Lightbulb Shellscript Interpreting

I am trying to interpret the following shellscript and am having a very difficult time. Could one of you Unix gurus pleasssseeee help me out? You just won't know how much of a life saver you would be for me.
Code:
PN=`basename "$0"`			# Program name
VER=`echo '$Revision: 1.2 $' | cut -d' ' -f2`

Usage () {
    echo "$PN - who is doing what, $VER (stv '95)
usage: $PN [-l] [-h] [user]
    -h: suppress the heading
    -l:	long form of output" >&2
    exit 1
}

Msg () {
    for i
    do echo "$PN: $i" >&2
    done
}

Fatal () { Msg "$@"; exit 1; }

LongOutput=no
Header=yes
while [ $# -gt 0 ]
do
    case "$1" in
	-l)	LongOutput=yes;;
	-h)	Header=no;;
	--)	shift; break;;
	-*)	Usage;;
	*)	break;;			# First file name
    esac
    shift
done

[ $# -gt 0 ] && User="$1"

if [ "$LongOutput" = no ]
then
    [ $Header = yes ] && {
	date
	uname -n
    }

    # Sample output of who:
    #	heiner   console Apr 26 08:18
    who |
	while read Name Tty Mon Day Time Host Rest
	do
	    [ -n "$User" -a "$User" != "$Name" ] && continue
	    echo "
$Tty	$Name	$Time"
	    case "$Tty" in
		*tty*)	T=`echo "$Tty" | sed -e 's:.*tty\(..\).*:\1:'`;;
		*)	T=`echo "$Tty" | sed -e 's:/dev/\(..\).*:\1:'`;;
	    esac

	    # Sample output of ps -c:
	    #	PID TT STAT  TIME COMMAND
	    #	327 p2 IW    0:19 ksh
	    ps -ct"$T" | tail +2 |
		while read pid tty stat time command
		do
		    echo "    $Tty	$pid	$time	$command"
		done
	done
else
    # Long form: use "w" output format
    if [ $Header = yes ]
    then FirstLine=1
    else FirstLine=3
    fi
    if [ -z "$User" ]
    then
	w
    else
	w | grep "$User"
    fi | tail +$FirstLine
fi

Thanks a million!!!!!!

added code tags for readability --oombera

Last edited by oombera; 02-18-2004 at 12:09 PM..
# 2  
Old 01-18-2002
Well, without going into a line by line
description, this script is apparently a
"whodo" script. Basically, it "maps" the logged
in userid's and tty's to specific processes,
hence "whodo" - "Who is doing what"

At least that's the way I read it Smilie
# 3  
Old 01-19-2002
Shellscript Interpreting

Thanks rwb1959 for replying. Unfortunately, that is just what I needed - a line by line description. I am trying to understand the various commands in Unix, but as I had stated I am having a terrible time doing it.

Thanks again.Smilie
# 4  
Old 01-19-2002
Do you have an UNIX shell programming reference books? There is a tremendous value to reading the first few chapters on syntax, variables and other shell script constructs... .especially pipes and filters. Using chains of filters by 'piping' the output of one command into the input of another is a very powerful construct. When you understand this construct (the use of the little "|" pipe) your shell-life gets much easier.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Interpreting multiple values from a variable

Hi, I am writing a shell script which will check the status of a resource in a cluster and then display nicely to a user running the script at command line. Basically the script runs a status command and then pulls certain keywords from the return and then should display a concise status. ... (5 Replies)
Discussion started by: chris01010
5 Replies

2. Solaris

Interpreting xntpdc output.

Hi. I wonder what the equal sign in front of the answer means. I have read man pages and googled but found no answer. xntpdc -p =15.5.64.3 15.5.2.51 3 512 377 0.02060 0.057426 0.04965Thanks. Jan (1 Reply)
Discussion started by: vettec3
1 Replies

3. Shell Programming and Scripting

Need help interpreting a function

Hi, i was reading through a sample coding and came across this function, can anyone pls help to interpret the code for me. Thank alot find_lines() { res=-1 if ; then grep -i "$@" $FILENAME res=$? fi return $res } (2 Replies)
Discussion started by: Cheranime
2 Replies

4. UNIX for Dummies Questions & Answers

interpreting netstat output

hi all, when I run- wcars1j5#netstat -an | grep 8090 127.0.0.1.8090 *.* 0 0 49152 0 LISTEN wcars1j5# 1. does this mean that no one is connected to this port? Regards, akash (1 Reply)
Discussion started by: akash_mahakode
1 Replies

5. Linux

Interpreting the encrypted shadow password?

We are currently using a script to copy the same encrypted password between our HP-UX and Solaris servers editing the trusted and shadow files directly. The encrypted password is only 13 characters long on both servers and decrypts the same way. Is there a way to copy this same string to Linux... (5 Replies)
Discussion started by: keelba
5 Replies

6. Solaris

solaris way if interpreting devices?

Hi all, I wanted to know the solaris way of interpreting devices? I mean i understand all those c0t0....stuff but when i start mounting devices , most of the times i get either a I/O error or it says that the directory does not exist. eg: I have a external usb hub to which i have connected... (1 Reply)
Discussion started by: wrapster
1 Replies

7. Solaris

help interpreting usermod man page

Hi, I put an expiration on a few id's that I want to remove now. From the man page -e expire Specify the future date on which a login can no longer be used; after this date, no user will be able to access this login. This option is useful ... (0 Replies)
Discussion started by: amheck
0 Replies

8. UNIX for Advanced & Expert Users

vmstats interpreting

We are having performance issues on an alpha4100 server. I can't paste a snapshot of my vmstat in here, but... We have 4gb of memory. The actual memory stays consistant around 306k. Free is dropping into the 120 area. Wire is around 206k consistantly. consistantly. My manual says that unix... (3 Replies)
Discussion started by: MizzGail
3 Replies

9. UNIX for Dummies Questions & Answers

Interpreting netstat -s

Are there any references I can look up for to interprete "netstat -s", especially those on TCP statistics. (6 Replies)
Discussion started by: deaniyoer
6 Replies
Login or Register to Ask a Question