System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Cron problems running a Perl script

IE Admins
Advisor

Cron problems running a Perl script

All,

I have a strange problem on a new Tru64 host I am configuring. I am attempting to run a simple Perl script from cron:
* * * * * /tmp/test.pl >> /tmp/test.log 2>&1

The output file contains no records, and cron log shows:
< testuser 296824 cr /tmp/test.pl >> /tmp/test.log 2>&1 rc=1 Fri Feb 13 07:02:00 2009

The contents of the Perl script is as follows, has correct permissions and runs OK interactively:
#!/usr/local/bin/perl -w
print "This is a test ";
exec ('date');

Obviously, rc=1 an error is occurring preventing my script from running.

I have tested the script and cron entries against another Tru64 host and a HP-UX host - both return expected results in the /tmp/test.log file.

I can force cron to run the script by changing the cron entry to:
/bin/ksh -c ". /etc/profile;/tmp/test.pl" >> /tmp/test.log 2>&1

My frustration is that I don't have to change the cron entry on my other test boxes to get the environment set up correctly. There's a difference in the OS environment setup on the new Tru64 host I am intalling ... where do I start looking?!?

Points gratefully awarded for any help!
4 REPLIES
Rob Leadbeater
Honored Contributor

Re: Cron problems running a Perl script

Hi,

I haven't tested your script, but I'll guess that this is an environment thing...

Try changing date to /usr/bin/date (or wherever date lives...)

Hope this helps,

Regards,

Rob
IE Admins
Advisor

Re: Cron problems running a Perl script

Thanks for the suggestion - I have updated the script with no luck.

The script doesn't seem to invoke at all - the print command does not return any output
Dennis Handly
Acclaimed Contributor

Re: Cron problems running a Perl script

>I can force cron to run the script by changing the cron entry to:
/bin/ksh -c ". /etc/profile;/tmp/test.pl"

This is one solution if you need your profile.
You could also create a ksh script that looks what variables are set and see which one perl needs, by trial and error.
Rob Leadbeater
Honored Contributor

Re: Cron problems running a Perl script

Hi,

Permissions on the log file maybe ?

Or maybe perl isn't in /usr/local/bin, although I'd expect that to cause it to fail interactively...

Cheers,

Rob