I need your help here. I wrote one PERL script for PHP application which needs to be run for every 5 mins. This script will call PHP program, which will fetch data from MySQL DB and will generate a excel report and will mail those reports to specific users. Every thing seems to be fine when I ran this script manually with the command (perl reports.pl). But when I set this Perl in a cron tab, nothing works and reports are not getting generated.
Details: perl script path /opt/app/deweb/web/EDI/Microsoft/reports.pl
this script will call PHP program (/opt/app/deweb/web/EDI/Microsoft/reports.php
)
content of script
#!/usr/local/bin/perl
use Net::FTP;
use File::Copy;
use POSIX;
@errorreport = `php /opt/app/deweb/web/EDI/Microsoft/reports.php`;
print "@errorreport
";
exit;
It is working perfectly when running Manually using command - perl reports.pl
No results, when set in CRON:
*/5 7-19 * * * /usr/local/bin/perl /opt/app/deweb/web/EDI/Microsoft/reports.pl
Please note that this crontab is under super user account named webserv and my login is having access to edit under this super user account. I'm editing this cron tab using command :: sudo -u webserv crontab -e
I would check the following:
sudo -u webserv perl reports.pl
? If not, fix the problem for the webserv
user (permissions or whatever) and it should work via cron too.which perl
using your login give you /usr/local/bin/perl
? If not, change the path to Perl in crontab
to what you got in which perl
to fix the problem.I found myself to be in the same situtation. After trying to find out the reason, I am almost sure about the reason this happens. Crontab does not have the same environment variables as you when running the script. You must be sure about paths. Try for example run your script like /perl-path /path-to-perl-script/script.pl outside the parent directory of the script and I am almost sure that your programm will not find some files. And as you call one php script from the perl script, it's possible to have the same problem with paths to your php script too.
So the solution is to use absolute paths and no relative.
Also at your perl script don't use php but /full-path-to-php for example:
@errorreport =
/usr/bin/php /opt/app/deweb/web/EDI/Microsoft/reports.php
;