Cron job not running (to do a trunk-check)

I have a php script to report un-registered trunks.

It runs fine when run on the command line and writes debug lines to a log file.

I have added

*/5 * * * * /var/lib/asterisk/agi-bin/trunk_check_registered.php

to /var/spool/cron/asterisk and the cron log /var/log/cron shows it being run every 5 minutes

CROND[10285]: (asterisk) CMD (/var/lib/asterisk/agi-bin/trunk_check_registered.php 

but it does not actually run.

I cannot find any errors in any log. Nothing is written to the debug log. Simulated trunk errors are not reported.

I have tried adding

> /var/log/debug2.log 2>&1)

at the end of the cron line in the hope there is some output but the file is not created.

The php file is owned by asterisk (and I have tried root) and permissions is set to 0777.

Any suggestions welcome.

I added a MAILTO line and got an error that I had no permission to create a log file in /var/log so I changed that to /tmp and not I get an debug2.log output:

Edit: ‘not’ in the line above should be ‘now’.

/bin/sh: /var/lib/asterisk/agi-bin/trunk_check_registered.php: /usr/bin/php^M: bad interpreter: No such file or directory

I don’t understand this.

My php script starts with ‘#!/usr/bin/php’ and file ‘trunk_check_registered.php’ certainly exists in folder ‘/var/lib/asterisk/agi-bin’

Sorry to suggest the bleeding obvious, BUT …
Did you restart the crond service after changing the cron file ?

I was not aware that was necessary.

In any event the cron entry is logged as having run - except it has not run:frowning_face:

You probably missed my 2nd post which shows that cron is trying to run it but fails - for reasons I don’t understand.

You copied the script from a DOS window.

open the file in ‘vi’ and do the following:

:1,$s/^v^m//g

Those are “control v” and “control m”. The “control v” tells vi that you want the next character to be inserted even if it is a control character. The “control m” will then be used as the “find” string. It will be replaced globally with nothing (deleted).

Thank you!!

Guilty as charged.

Well spotted!

I’m using WinSCP so it was easy enough to change it to Unix format.

Must be more careful in future.

Again many thanks.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.