Welcome to WebmasterWorld Guest from 54.226.27.104

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Php Script Not Running Via cron?

     

kieranmullen

5:15 am on Jul 22, 2009 (gmt 0)

5+ Year Member



I have a script that runs from the shell fine and it appears from the crob logs that it is being run sucessfully. When the script is run it is supposed to send me an email on a condition and to test the script I have created that condition. As it is now it will only email me when performed manually. I do not knwo what to do next. Appreciate any ideas...

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*

jamie

4:04 pm on Jul 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try telling the system which program needs to run the script - in this case php - so the entry becomes:

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

kieranmullen

4:34 pm on Jul 22, 2009 (gmt 0)

5+ Year Member



Thank you for the info.

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

kieranmullen

6:11 pm on Jul 22, 2009 (gmt 0)

5+ Year Member



I piped the output to a text file. I did get a "Array
(
)"

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]

g1smd

7:55 pm on Jul 22, 2009 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I had a lot of 'fun' getting PHP scripts to run in cron:

00,15,30,60 * * * * [b]/usr/bin/php[/b] /var/www/nnnnnnnn.eu/cronscript/nnnn.php [b]>>[/b] /home/nnnnnn/cronlogs/nncron.log

kieranmullen

8:06 pm on Jul 22, 2009 (gmt 0)

5+ Year Member



g1smd - What woudl you suggest I do? The file being executed is not in a web accessible directory. Thank you
 

Featured Threads

Hot Threads This Week

Hot Threads This Month