Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ksh somehow became sh in script?

0 views
Skip to first unread message

steve johnson

unread,
Apr 30, 1996, 3:00:00 AM4/30/96
to

i'll preface this post just like i did my previous one:
i'm not a "real" sysadmin, but i'm asked to do some sysadmin
stuff once in a while.

anyway, due to the vagaries of the way things work here i
have to clean up zombies left by users a couple of times a
week. for some reason one user in particular leaves more
than most.

so, not being a "real" sysadmin and not being real swift with
awk i decided to write a script for him that will kill his
zombies everytime he logs on. looks like this:

#!/bin/ksh

ps -ef |grep jjpan > jjfile
JJFILE=jjfile

awk `BEGIN { FS=" " }
{
if ( $5 !~ /[0-9][0-9]:[0-9][0-9]:[0-09][0-9]/ ) {
print $2
}
}' $JJFILE > JJPID

for i in $(cat JJPID)
do
kill $i
done

now i'm sure there are many ways of doing this more elegantly, but
like i said, i'm not an awk guru. anyway, i couldn't figure out
why it didn't work. then on a whim i changed $(cat JJPID) to
`cat JJPID` (/bin/sh syntax) and lo and behold it worked fine.

so: what happened to my invocation of #!/bin/ksh at the beginning
of the script? why did i have to return to sh syntax?

--

"The different versions of the UN*X brand operating system
are numbered in a logical sequence: 5, 6, 7, 2, 2.9, 3,
4.0, III, 4.1, V, 4.2, V.2, and 4.3."

- alan filipski


Vaughan Marks

unread,
May 2, 1996, 3:00:00 AM5/2/96
to

In article <Pine.SUN.3.91.960430...@defiant.gsfc.nasa.gov> steve johnson <sjoh...@strfleet.gsfc.nasa.gov> writes:
>
> so, not being a "real" sysadmin and not being real swift with
> awk i decided to write a script for him that will kill his
> zombies everytime he logs on. looks like this:
>
> #!/bin/ksh
>
> ps -ef |grep jjpan > jjfile
> JJFILE=jjfile
>
> awk `BEGIN { FS=" " }
> {
> if ( $5 !~ /[0-9][0-9]:[0-9][0-9]:[0-09][0-9]/ ) {
> print $2
> }
> }' $JJFILE > JJPID
>
> for i in $(cat JJPID)
> do
> kill $i
> done

Try:

ps -ef | grep jjpan | grep -v grep | awk '{print $2}' | xargs kill -9 &

Interpetation of #!/bin/ksh depends on the hardware you are using---maybe
your script was really being executed in bourne shell...
--
Cheers,
vaughan

Larry Dighera (larry@mtndew.com)

unread,
May 3, 1996, 3:00:00 AM5/3/96
to mtndew!...@strfleet.gsfc.nasa.gov
[steve's script begins: #!/bin/ksh]

>i couldn't figure out
>why it didn't work. then on a whim i changed $(cat JJPID) to
>`cat JJPID` (/bin/sh syntax) and lo and behold it worked fine.
>
>so: what happened to my invocation of #!/bin/ksh at the beginning
>of the script? why did i have to return to sh syntax?

Some versions of UNIX don't honor the #!/bin/ksh mechanism. To
overcome this, you can make this the second line in your script:

[ "$PS3" ] || exec /bin/ksh $0 $*

That should insure that it is run by ksh.

Larry Dighera

--
Larry Dighera
la...@mtndew.com

TELE: (714) 842-6348; (714) 842-5851: Public Access guest & bbs logins.

Richard Puchmayer

unread,
May 8, 1996, 3:00:00 AM5/8/96
to

In article <Pine.SUN.3.91.960430...@defiant.gsfc.nasa.gov>,
steve johnson <sjoh...@strfleet.gsfc.nasa.gov> writes:
>
[snip]

>
>so, not being a "real" sysadmin and not being real swift with
>awk i decided to write a script for him that will kill his
>zombies everytime he logs on. looks like this:
>
>#!/bin/ksh
>
[snip]

Also, #!/bin/ksh must be the first line for this mechanism to work.

RiP

--
- Richard....@nautronix.com.au | NAUTRONIX Ltd. -
- Tel: +61 [0]9 430 5900, Fax: 430 5901 | 108 Marine Tce. -
- These are ramblings of an insane mind. | Fremantle, WA 6160 -
- "In summary, N is Richardian iff N is not Richardian." - Fortune -


0 new messages