[comp.unix.questions] awk script problems <sigh>

shawn@litsun.epfl.ch (Shawn Koppenhoefer) (03/20/91)

I am trying to set something up such that if my xdm process dies
the xdm-pid file is removed in the /tmp directory.
So far I've got: ps -aux | grep xdm | grep -v grep | egrep "0 (xdm)"
which gives me the line:

root       122  0.0  0.0   88    0 ?  IW   12:43   0:00 xdm


if the xdm process exists. Now, I figured that if I passed this into
the following awk script the /tmp/xdm-pid file would be erased. but
instead I get an error... what's wrong?!
-----------------my executable file looks like the following

awk '
$11 == "xdm" { touch thisfile }
'

I use "touch thisfile" to see if the file "thisfile" is created, but
it never is! (later I'll replace "touch thisfile" with "rm
/tmp/xdm-pid"

--

_____________________________________________________________________________
| shawn@litsun.epfl.ch     -.-  KLEIN BOTTLE FOR SALE ...            \#######
| Shawn Edwin Koppenhoefer \_/                    ... enquire within  \######
| Sun System-Manager, EPFL (Ecole Polytechnique Federale de Lausanne)  \#####
| EL-Ecublens, CH 1015 Lausanne SWITZERLAND (021)6934703 telefax=474660 \####
| from Canada dial: 1-41-21-693-4703 ____________________________________|###
|___________________________________/

weimer@garden.kodak.COM (Gary Weimer (588-0953)) (03/21/91)

In article <SHAWN.91Mar20141448@litsun.epfl.ch>, shawn@litsun.epfl.ch
(Shawn Koppenhoefer) writes:
...
|> So far I've got: ps -aux | grep xdm | grep -v grep | egrep "0 (xdm)"
|> which gives me the line:
|>     root       122  0.0  0.0   88    0 ?  IW   12:43   0:00 xdm
|> if the xdm process exists. Now, I figured that if I passed this into
|> the following awk script the /tmp/xdm-pid file would be erased. but
|> instead I get an error... what's wrong?!
|> -----------------my executable file looks like the following
|> 
|> awk '
|> $11 == "xdm" { touch thisfile }
|> '
|> 
|> I use "touch thisfile" to see if the file "thisfile" is created, but
|> it never is! (later I'll replace "touch thisfile" with "rm
|> /tmp/xdm-pid"

It would help if you told us what the error is...

If you really have the awk command spread over three lines, that could
be the cause of your error.
touch is not an awk command, so you can't use it inside the curly
brackets (rm is not an awk command either).
Why do you even need awk? If the above ps line returns something, the
process is still running; otherwise, it has died. So...

#!/bin/csh -fb
set x=`ps -aux | grep xdm | grep -v grep`
if ("$x" == "") rm /tmp/xdm-pid       # remove file when xdm dies

What was the last egrep for, anyway???

weimer@ssd.kodak.com ( Gary Weimer )