Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crontab script giving error 2

Status
Not open for further replies.

jrig

Technical User
Sep 5, 2006
36
US
I have a perl script running as a cronjob that is giving a strange error - 'xxxx: command not found', in the system email I get. I think this is odd since the script runs fine from the command line. I'm not the admin on this box, so the script is a crontab entry this also means I can't access the cron logs.

Does a script running as cron have a different $path than a script running from the command line? I have modofied my $path from its 'out of the box' setting. Any ideas would be appreciated. TIA

Joe
 
Hello,

this is a common problem with cron jobs; they haven't got the same environment as a job started from command line.
In case of 'xxxx: command not found', it is (most probably) the $PATH variable.
So you may either define $PATH at the beginning of your cron job, or call your program xxxx with full path /path/to/xxxx .

hope this helps
 
Thanks hoinz - sound advice.

Do you know if there's anyway to import my environment for this particular script? I'm guessing that it is setup this way for security reasons? I have tracked the error I was getting from above to a system command issued by the perl script. I gave the full path to the app my script was calling, which is I why I was confused about the error.

Apparently the called application is dependent on several other files not in the (cron's) path. Tracking down ALL those depencies could potentially be a major pita. If this question is better suited for the perl forums, please mention and I will cross-post. Thanks again-
 
Hi,

if you want to import your environment, then to source is the correct term for that. It is a Unix/Linux thing, and so you are at the right place in this forum.

You may make environment variables defined in some file (like .profile, or .kshrc) available to your current process by sourcing like this:
. /path/to/.profile
. /path/to/.kshrc
(Note that this will not work for C shell csh; it will work for sh, ksh, bash and others.)
When you log on to Linux, some files (depending on your shell) will always be sourced like this. But cron won't do it, unless you tell it to do so.

hope this helps
 
Hello again,

one more possible problem just comes to my mind:
In Linux cron jobs are often executed by user root.
Make sure you use the same user as from command line.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top