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

Reply via email to