The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
solaris way if interpreting devices? wrapster SUN Solaris 1 01-24-2008 07:53 PM
interpreting email log: ndel= mstarcom UNIX for Dummies Questions & Answers 1 12-11-2007 11:01 AM
help interpreting usermod man page amheck SUN Solaris 0 06-08-2006 03:29 PM
vmstats interpreting MizzGail UNIX for Advanced & Expert Users 3 02-22-2002 12:56 PM
Interpreting netstat -s deaniyoer UNIX for Dummies Questions & Answers 6 07-25-2001 08:48 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-18-2002
Ann Ann is offline
Registered User
  
 

Join Date: Jan 2002
Location: Georgia
Posts: 2
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 (permalink)  
Old 01-18-2002
rwb1959's Avatar
rwb1959 rwb1959 is offline
Registered User
  
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
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
  #3 (permalink)  
Old 01-19-2002
Ann Ann is offline
Registered User
  
 

Join Date: Jan 2002
Location: Georgia
Posts: 2
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.
  #4 (permalink)  
Old 01-19-2002
Neo's Avatar
Neo Neo is offline Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,709
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0