You are not logged in.
Hello. I have made a script which needs to be "daemonized". But the daemon can only be started, not stopped. Don't know why, really.
This is the daemon script:
mladen ~ $ cat /etc/rc.d/cipcd
#!/bin/bash. /etc/rc.conf
. /etc/rc.d/functionsPID=`pidof -o %PPID /usr/bin/cipcd`
case "$1" in
start)
stat_busy "Starting CIPC Daemon"
[ -z "$PID" ] && /usr/bin/cipcd 2>&1 &
if [ $? -gt 0 ]; then
stat_fail
else
add_daemon cipcd
stat_done
fi
;;
stop)
stat_busy "Stopping CIPC Daemon"
[ ! -z "$PID" ] && kill $PID &>/dev/null
if [ $? -gt 0 ]; then
stat_fail
else
rm_daemon cipcd
stat_done
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
exit 0
This is the script which does the job (checks if my IP address has changed, and if it is, update it on the free domain server):
mladen ~ $ cat /usr/bin/cipcd
#!/bin/bash
interval=600
sip=`lynx -dump 'http://192.168.1.1:8080/rpServiceStatus.html' -auth=admin:admin | grep 'PVC-0' | cut -d ' ' -f7`
while :
do
cip=`lynx -dump 'http://192.168.1.1:8080/rpServiceStatus.html' -auth=admin:admin | grep 'PVC-0' | cut -d ' ' -f7`;
if (test "$sip" != "$cip") then
`lynx -dump 'http://www.some address.com/blah blah'`&>/dev/null
sip=$cip;
fi
sleep "$interval"s ;
done
Any help appreciated...
Last edited by Demon (2010-10-30 10:03:32)
Offline
I believe the following line is failing:
PID=`pidof -o %PPID /usr/bin/cipcd`
Have you tried echoing the value of PID to see what value it has? I don't think it's returning a value.
Offline
Thank you, moniker117, I've fixed the daemon script, now everything is ok.
In case someone is interested:
mladen ~ $ cat /etc/rc.d/cipcd
#!/bin/bash. /etc/rc.conf
. /etc/rc.d/functions#PID="$(cat /var/run/cipcd.pid 2>/dev/null)"
PID="$(ps -A | grep cipcb | cut -d ' ' -f2)"case "$1" in
start)
stat_busy "Starting CIPC Daemon"
[ -z "$PID" ] && /usr/bin/cipcb 2>/dev/null &
if [ $? -gt 0 ]; then
stat_fail
else
add_daemon cipcd
stat_done
fi
;;
stop)
stat_busy "Stoping CIPC Daemon"
[ ! -z "$PID" ] && kill $PID &> /dev/null
if [ $? -gt 0 ]; then
stat_fail
else
rm_daemon cipcd
stat_done
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
status)
if [ ! -z "$PID" ]; then
echo "The script is running."
else
echo "The script is not running."
fi
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
exit 0
mladen ~ $ cat /usr/bin/cipcb
#!/bin/bashinterval=600
#IP address check - HUAWEI SmartAX MT882 ADSL modem
sip=`lynx -dump 'http://192.168.1.1:8080/rpServiceStatus.html' -auth=admin:admin | grep 'PVC-0' | cut -d ' ' -f7`while :
do
cip=`lynx -dump 'http://192.168.1.1:8080/rpServiceStatus.html' -auth=admin:admin | grep 'PVC-0' | cut -d ' ' -f7`;if (test "$sip" != "$cip") then
`lynx -dump 'http://www.freedomain.co.nr/dyna.php?do … ass=******'`&>/dev/null
sip=$cip;
fi
sleep "$interval"s ;
done
Offline