tags:

views:

86

answers:

3

Is it possible to know the pid of the iwevent process in the following bash script:

#!/bin/sh
( iwevent | logger -t IWEVENT ) &
echo the pid is: ???

Note that iwevent run until ctrl-c signal.

FYI. I run this script in a /etc/network/interfaces "up" statement and I want to kill the running iwevent process in the related "down" statement. My aim is to log wireless events.

+1  A: 
pid=$!

See here

eumiro
This would return the PID of the last program in the pipeline, i.e. the PID of `logger`.
Roman Cheplyaka
@Roman Cheplyaka:+1
Aboelnour
+1  A: 

check "pidof" function
see this http://en.wikipedia.org/wiki/Pidof
and check the man page: man pidof

Aboelnour
but if several iwevent are running, I am not sure to get the right pid
Soubok
+2  A: 

Something like this should do the trick:

#!/bin/sh
( { iwevent & printf "The pid is %s\n" $! >&3; } | logger -t IWEVENT ) 3>&1 &

If you need it in a variable, read the output of the above.

Roman Cheplyaka