On Thu, 30 Oct 2003 08:37:42 +1300
Luuk Paulussen <[EMAIL PROTECTED]> wrote:

> You could do something like "ps ax | grep tail" and get the first field of 
> the resulting line (not sure what the best tool is for that, probably 
> something like cut)

no good if you have other tails running, or other users have other tails
running....

> 
> >From: Daniel Fone <[EMAIL PROTECTED]>
> >Reply-To: [EMAIL PROTECTED]
> >To: [EMAIL PROTECTED]
> >Subject: Bash scripting
> >Date: Wed, 29 Oct 2003 10:03:31 +1300
> >
> >Hi guys,
> >
> >I was wondering if anyone could help me out with this...
> >I have a bash script, which generates a command like so:
> >CMD="tail -f /var/log/messages | /usr/bin/perl -n /tmp/sentry_1.pl"
> >
> >Good so far. I need to execute this command asyncronosly (eg in the
> >background). So I run eval "$CMD &" which works fine. The commands get
> >"forked" so that ps -afx returns:
> >3272 pts/0    S      0:00 tail -f /var/log/messages.2
> >3273 pts/0    S      0:00 /usr/bin/perl -n /tmp/sentry_1.pl
> >
> >The tricky part is that I need to store the PID of the command so I can 
> >kill
> >it later. The $! variable is great but it only contains the pid of the perl
> >script (eg 3273) which, when killed, leaves the tail alive! Is there anyway 
> >I
> >can get the pid of the tail?
> >
> >I thought an alternative would be to run "sh -c $CMD &" which also works 
> >and
> >gives us:
> >3648 pts/0    S      0:00 sh -c [...] | /usr/bin/perl -n /tmp/sentry_1.pl
> >3651 pts/0    S      0:00  \_ tail -f /var/log/messages.2
> >3652 pts/0    S      0:00  \_ /usr/bin/perl -n /tmp/sentry_1.pl
> >However, when I kill the sh process, both the tail and the perl remain
> >running.
> >
> >Any ideas?
> >
> >Daniel
> >
> 
> _________________________________________________________________
> Need more speed?  Get Xtra Jetstream @  
> http://www.xtra.co.nz/products/0,,5803,00.html !
> 

-- 
Nick Rout <[EMAIL PROTECTED]>

Reply via email to