Trying to get nagios to monitor asterisk


I’m trying to get cron to run a bash acript to pull out an iax registration we have so I can detect when we lose connection with our voip provider.

The following minimal script shows where my problem is (it’s running on Centos 5)

asterisk -r -x “iax2 show registry” >/root/log

The script has execute rights for user group and other and works as expected when run interactivly by the root account. However, when run via cron, it leaves a zero length file behind and no error messages that I have been able to find. The job was added to cron via crontab as user root with the following line

*/1 * * * * /root/check-asterisk

I have hunted through google but have not found any answers.

If anyone has any ideas on whats happening, it would be appreciated.


Have you tried disabling selinux? I’ve had strange problems like that before which have been solved once it’s been disabled.

Yes, selinux is disabled. I’ve had that cause problems before.

For the moment I have it running using the batch command, a loop and sleep, but that’s not an ideal solution. I’m still keen on being able to get it working under cron.


Fisrt thing for running as a cron is to use the full path not just “asterisk”


ianplain, thanks… that fixed it. My script now looks like this


NEHOS=/usr/bin/nslookup|/bin/grep -v \# | /bin/grep Address | /bin/sed "s/Address\: //"

/usr/sbin/asterisk -r -x “iax2 show registry” | /bin/grep $NEHOS | /bin/grep Registered > /root/log2

if [ “$?” = “0” ]; then
echo “OK, it’s registered” > /home/nagios/nehos-registered
chown nagios:nagios /home/nagios/nehos-registered
echo “OK, it’s registered” >/root/log
echo “It’s not registered” >/root/log

I confirmed the path under cron is severly truncated. Is there any clean way to have the usual path in place. It seems odd to have to specify the full path for each program you’re calling and it doesnt make it too portable.

The only think I could think of would be to do something like

$GREP blah blah