Forum Moderators: coopster
The script has a user nobody:nobody
Script works fine if fun manually #/etc/asterisk/check-status.php
crontab -e
1,11,21,31,41,51 * * * * /etc/asterisk/check-status.php >/dev/null 2>&1
root@cpanel3 [/]# tail /var/log/cron
Jul 21 21:21:01 cpanel3 crond[5633]: (root) CMD (/etc/asterisk/check-status.php >/dev/null 2>&1)
root@cpanel3 [~]# cat /proc/version
Linux version 2.6.9-67.0.15.EL (mockbuild@builder10.centos.org) (gcc version 3.4.6 20060404 (Red Hat 3.4.6-9)) #1 Thu May 8 10:38:13 EDT 2008
root@cpanel3 [~]# setenforce
usage: setenforce [ Enforcing ¦ Permissive ¦ 1 ¦ 0 ]
root@cpanel3 [~]# getenforce Disabled
ls -la /etc/asterisk/check-status.php
-rwxrwxr-x 1 nobody nobody 2178 Jul 10 2008 /etc/asterisk/check-status.php*
1,11,21,31,41,51 * * * * php /etc/asterisk/check-status.php >/dev/null 2>&1
you may even have to put the full path to php, e.g. /usr/local/bin/php (type "which php" to find out where yours is)
good luck
I edited crontab via crontab -e afterward it said crontab:installing new crontab. I changed it also to run every five minutes.
Also I also checked to make sure that /usr/local/bin/php /etc/asterisk/check-status.php worked via the command prompt and it worked fine
/usr/local/bin/php /etc/asterisk/check-status.php
root@cpanel3 [~]# crontab -l
1,5,10,15,20,25,30,35,40,45,50,55,59 * * * * /usr/local/bin/php /etc/asterisk/check-status.php >/dev/null 2>&1
I have noticed there is no closing php tag so I closed it but it did not make a difference.
[codes]#!/usr/local/bin/php
<?php
define('EMAIL' , 'kieranmullen@gmail.com');
define('IGNORE-GENERIC' , true);
$errors = array();
//Start cehcking Zaptel
$line = shell_exec('asterisk -rx "zap show status"');
$lines = explode("\n",$line);
array_shift($lines); //Remove the headers that are the first line.
array_pop($lines); //The last line is junk.
foreach ( $lines as $x ) {
$x = preg_replace('¦[ ][ ]+¦',"\t",$x);
list($board,$alarm,$irq) = explode("\t",$x);
if ( $alarm != "OK" ) {
if ( !IGNORE-GENERIC ¦¦ ( strpos($board,'Generic') === false ))
$errors[] = "Zaptel Card $board ($irq) is alarm $alarm";
}
}
//Start checking IAX2
$line = shell_exec('asterisk -rx "iax2 show registry"');
$lines = explode("\n",$line);
array_shift($lines); //Remove the headers that are the first line.
array_pop($lines); //The last line is junk.
foreach ( $lines as $x ) {
$x = preg_replace('¦[ ]+¦',"\t",$x);
list($host,$username,$dns,$preceived,$refresh,$state) = explode("\t",$x);
if ( $state != "Registered" ) {
$errors[] = "IAX $host ($username) is in state $state";
}
}
//Start checking Registry
$line = shell_exec('asterisk -rx "sip show registry"');
$lines = explode("\n",$line);
array_shift($lines); //Remove the headers that are the first line.
array_pop($lines); //The last line is junk.
foreach ( $lines as $x ) {
$x = preg_replace('¦[ ]+¦',"\t",$x);
list($host,$username,$refresh,$state) = explode("\t",$x);
if ( $state != "Registered" ) {
$errors[] = "Trunk $host ($username) is in state $state";
}
}
if ( count($errors) > 0 ) {
$h = fopen('/etc/asterisk/asteriskmonitor','a+');
foreach($errors as $x) {
fwrite($h,date("M d H:i:s") . ' ' . $x . "\n");
}
fclose($h);
$message = array(
'There where some problems with your Asterisk Registry',
'--------------------------------------------------------'
);
foreach ( $errors as $x )
$message[] = $x;
$message = implode("\r\n",$message);
$headers = implode("\r\n",array(
'From: monitord@omain.net'
));
mail(EMAIL,'Asterisk Registry Monitor2 - Link Down',$message,$headers);
}
print_r($errors);[codes]