LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   only run cronjob when asteriks voip gives 0 on channels (http://www.linuxquestions.org/questions/programming-9/only-run-cronjob-when-asteriks-voip-gives-0-on-channels-675043/)

1c3c0ld 10-08-2008 09:04 AM

only run cronjob when asteriks voip gives 0 on channels
 
hello,

i have set up a asteriks voip and add a cronjob to send the output of a specific command to my email after the cronjob shutdown -r now.
now i need a script that prevents the cronjob (reboot and email) from being executed if this command: asteriks -rx "show channels" states active connections(to prevent active calls being terminated)
the output of the command above(asteriks -rx "show channels") is as follows(if there are no calls)

Code:

channel                location          state    application(data)
0 active channels
0 active calls

i know this sounds complicated but what it comes down to that i basically need some kind of if and else statement in crontab

hope some 1 can help me with this

regards,

carltm 10-08-2008 07:07 PM

The easy way is to write a script. Something like this.
Then run this script from the cronjob. When the script is
run, it waits until after both channels are clear before
rebooting.


#!/bin/sh
# @(#) reboot-voip reboot voip server after calls clear

until [ `asterisk -rx "show channels" | grep "^0 act" | wc -l` -eq 2 ]
do
sleep 5
done

shutdown -r now


All times are GMT -5. The time now is 01:58 PM.