|Perl Monk, Perl Meditation|
The "Perl script on command line works but as cronjob it fails" story revisitedby karlgoethebier (Parson)
|on Mar 05, 2013 at 11:01 UTC||Need Help??|
karlgoethebier has asked for the
wisdom of the Perl Monks concerning the following question:
Hi all, this is an old story, but it's still sometimes surprising:
What i did
I wrote some perl....disaster.pl --foo bar
...and a shell wrapper for cron:
I've got a test machine and a production machine which are totally identical.
It is impossible to test on prod.
OS is SLES11.
Running the perl script as well as the shell wrapper via commandline or cron on test leads to the expected results.
The UID on test is root.
On prod the UID is another, let's say karl - for some reason.
On prod the cron job (shell wrapper) gets executed and cron writes this to syslog but the perl script doesn't write to syslog and doesn't mail.
But when i change the shell wrapper on prod to.../usr/bin/perl /usr/local/bin/disaster.pl --foo bar > /dev/null 2>&1
But why - what do i miss?
N.B.: Perl code, shell wrapper and crontab are OK, that's why i didn't post more details.
I tried all the given hints (most of them i did before posting) but i couldn't figure out the reason for this issue.
But fortunately i had solution: adding /usr/bin/perl in the shell wrapper did the job, although /usr/bin is already in the path when cron runs the script under my uid.
Thanks to all that helped.