Reputation: 1
I have a perl script and I scheduled it to run daily through crontab. The script is working fine if executed. But while executing through crontab, it's posting error mail to my mailbox.
Is there any thing that I should modify to successfully execute the script through crontab?
Upvotes: 0
Views: 357
Reputation: 1567
It could be a $PATH
problem. Ensure that your Perl script either is on a place mentioned by $PATH
, or has an absolute path in the crontab. This is also valid for any script or program that you run in the Perl script. The $PATH
variable usually has to be set inside the crontab file.
It could be a file used in the Perl script having relative path, which could work when executed manually, but fail when run by cron
(different working directories).
Does the Perl script have execute permissions (the x
mode bit set)? This is not necessary when it's run with perl /path/to/script.pl
, but would fail when it's run with /path/to/script.pl
.
EDITED:
Suggestions for how to fix:
Add to $PATH
in the crontab (for the sample script /path/to/script.pl
):
PATH=/bin:/usr/bin:/path/to
Remember to include other needed paths as well (e.g. /bin
and /usr/ucb
).
Chances are there already is a PATH
definition in the file. In that case, just append your path to it.
Alternatively, you can specify full path in the cron job line, e.g.:
17 * * * * root /path/to/script.pl
To fix permissions:
chmod a+r+x /path/to/script.pl
Upvotes: 2