Re: to find the PID of a background ksh function



"mobidyc" <mobidyc@xxxxxxx> a écrit dans le message de
news:elc46t$5mv$1@xxxxxxxxxxxxxxxxxxxxxx
Hello,

i can't obtain the PID of a background ksh function, could you help me
to find the correct way please? :

##########PROGRAM##############
#!/bin/ksh
SERVERS="nr0u0151 nr0y0031 nr0u0160"
TMPDIR=/tmp
DEBUG=true

remote_command () {
SERVER_bg="${1}"
shift
COMMAND_bg="${@}"

ssh -f -lroot $SERVER_bg \"${COMMAND_bg}\" >> $TMPDIR/$SERVER_bg
2>&1
if [ "$?" != "0" ]
then
echo "ssherr" >> $TMPDIR/$SERVER_bg
remsh -l root $SERVER_bg "${COMMAND_bg}" >> $TMPDIR/$SERVER_bg
2>&1
if [ "$?" != "0" ]
then
echo "rsherr" >> $TMPDIR/$SERVER_bg
fi
fi
}

for SERVER in $SERVERS
do
touch $TMPDIR/$SERVER
chmod 600 $TMPDIR/$SERVER

remote_command $SERVER "uname -n ; uname -s" & # Backgrounded
process here
PID="$!"
eval ${SERVER}_PID=\$PID
[ -n "DEBUG" ] && {
eval echo eval: ${SERVER}_PID=\$PID
echo "PS pid: $(ps -ef -o pid,args |awk '$1 ~ /^'"$PID"'$/')"
echo "PS cmd: $(ps -ef -o pid,args |grep "ssh -f -l root
$SERVER"
|grep -v grep)"
}
done
##########END PROGRAM##########

result:
# ./t
eval: nr0u0151_PID=15695
PS pid: 15695 /bin/ksh ./t
PS cmd: 15697 ssh -f -lroot nr0u0151 "uname -n ; uname -s"
eval: nr0y0031_PID=15737
PS pid: 15737 /bin/ksh ./t
PS cmd: 15738 ssh -f -lroot nr0y0031 "uname -n ; uname -s"
eval: nr0u0160_PID=15768
PS pid: 15768 /bin/ksh ./t
PS cmd: 15771 ssh -f -lroot nr0u0160 "uname -n ; uname -s"

as you can see, the "$!" value is not the correct value, it's the
value
of the mail program.
of course, i would liked to write 'of the main program' ;)


please help me to understand!!!

--
Regards,
Mobidyc

i have resolved my problem by creating a program instead of a function
bye




.