Sponsored Content
Full Discussion: Shellscript Interpreting
Top Forums UNIX for Dummies Questions & Answers Shellscript Interpreting Post 13571 by Ann on Friday 18th of January 2002 10:27:50 PM
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..
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
echo(1B)					     SunOS/BSD Compatibility Package Commands						  echo(1B)

NAME
echo - echo arguments to standard output SYNOPSIS
/usr/ucb/echo [-n] [argument] DESCRIPTION
echo writes its arguments, separated by BLANKs and terminated by a NEWLINE, to the standard output. echo is useful for producing diagnostics in command files and for sending known data into a pipe, and for displaying the contents of envi- ronment variables. For example, you can use echo to determine how many subdirectories below the root directory (/) is your current directory, as follows: o echo your current-working-directory's full pathname o pipe the output through tr to translate the path's embedded slash-characters into space-characters o pipe that output through wc -w for a count of the names in your path. example% /usr/bin/echo "echo $PWD | tr '/' ' ' | wc -w" See tr(1) and wc(1) for their functionality. The shells csh(1), ksh(1), and sh(1), each have an echo built-in command, which, by default, will have precedence, and will be invoked if the user calls echo without a full pathname. /usr/ucb/echo and csh's echo() have an -n option, but do not understand back-slashed escape characters. sh's echo(), ksh's echo(), and /usr/bin/echo, on the other hand, understand the black-slashed escape characters, and ksh's echo() also understands a as the audible bell character; however, these commands do not have an -n option. OPTIONS
-n Do not add the NEWLINE to the output. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), echo(1), ksh(1), sh(1), tr(1), wc(1), attributes(5) NOTES
The -n option is a transition aid for BSD applications, and may not be supported in future releases. SunOS 5.11 3 Aug 1994 echo(1B)
All times are GMT -4. The time now is 06:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy