I came up with this:
(instead of starting dhcpd I am testing with mahjongg)
It goes like this:
when there is no connection the script will start mahjongg
when the connection come up again mahjongg gets killed
that part works fine.
But when the connection is ok, the script tryes to kill a process that is not there.. it is supposed to exit. Can anyone with a sharp eye see where my error is?
Regards KimJensen
A=`ps auxww |grep /usr/games/mahjongg|grep -v grep |awk '{print $2}'` > /dev/null #process ID of mahjongg
ping 10.0.0.2 -c3 -W3 > /dev/null
if [[ $? -eq 1 && -z $A ]] #if connection error and mahjongg pid is empty
then /usr/games/mahjongg & #then start mahjongg
elif
[[ $? -eq 0 && -z $A ]] # if connection ok and mahjongg pid is empty
then exit #do nothing
else kill $A # else kill mahjongg pid
fi
---------- Post updated at 12:49 PM ---------- Previous update was at 08:47 AM ----------
I solved it like this:
#!/bin/bash
A=`ps auxww |grep /usr/games/mahjongg|grep -v grep|awk '{print $2}'`
ping 10.0.0.2 -c3 -W3 > /dev/null
B=$?
if [[ $B -eq 1 && -z $A ]]
then /usr/games/mahjongg &
elif
[[ $B -eq 1 && -n $A ]]
then exit
elif
[[ $B -eq 0 && -z $A ]]
then exit
else kill $A
fi
-not very pretty but it works