![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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
added code tags for readability --oombera Last edited by oombera; 02-18-2004 at 12:09 PM.. |
|
||||
|
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. ![]() |
|
|||||
|
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.
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|