|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
Executing a script through a cron job
I have a script file that gives the correct output when manually run at the command prompt: perl nov.pl
But, when I schedule it in a cron job like: 0 15 * 7 5 perl /path/nov.pl, it does not execute. The other cron jobs work fine and I have even added new cron jobs to execute different perl scripts, and everything works. I don't understand why this particular perl script does not execute when given in a cron job. Can someone please help me out with this issue. Thank you. |
|
#2
|
|||
|
|||
|
If the first line of your script is a she-bang something like:
Code:
#!/usr/contrib/perl You do not need the "perl" part of the cron command, which is likely what is causing your problem. cron doesn't necessarily have a PATH environment variable from the getgo. |
|
#3
|
|||
|
|||
|
^^^^his idea is better.
|
|
#4
|
|||
|
|||
|
Jim,
I deleted the perl in the cron job command, but it still did not work. I have other cron jobs that specify perl in the command line and they work fine. I have been on it for a day now and I don't see any problem with the perl file. There are Switch, if statements in the file, just for your info. Please let me know what do you think might be the problem. Thank you. |
|
#5
|
|||
|
|||
|
Your environment (environment variables) are not set right,
or your code is failing because of file permissions. Assuming you tested the heck out of your perl code. Put this script up for testing: Code:
#!/bin/ksh set > /tmp/cronpath.txt 1. Compare the envrionment variables in the cronpath.txt with a set command issued by you when you are testing the perl script. 2. If nothing turns up, it has to be permissions. Code:
0 15 * 7 5 perl /path/nov.pl 2>/tmp/cronerrors.txt See what you get in cronerrors.txt |
|
#6
|
|||
|
|||
|
hey Jim,
that is an excellent idea. Right on time. So many people run into problems with cron that boil down to either the privileges or the environment of the cron user. Using set and diff helps make the situation plain as day. I'd almost go so far as to suggest making that last post "sticky". -Steven |
|
#7
|
|||
|
|||
|
Jim,
The cronerrors.txt file gave me an error that the Switch functionality is not supported. So I changed the Switch statement to an if-elsif statement. Its working perfectly now. Thanks a lot for your help. Its a big relief. -Yogesh. |
|
#8
|
|||
|
|||
|
Jim,
I still don't understand how did the script execute at the command line (perl nov.pl) but gave an error for the Switch statement when executed through the cron job. -Yogesh. |
|
#9
|
|||
|
|||
|
A guess -
try: Code:
echo $SHLIB_PATH This is the search path that dld (the dynamic loader) uses to find modules. perl uses dld to load shared libraries. If you assume there are some different versions of perl (GNU vs something else) on your box, then changing or not having SHLIB_PATH or some entry in PATH would make you use different run time libraries. One RTL has switch - the other can't find it. libperl is the library. You can do this to see what the cron job is doing - but you need TONS of disk space - find either tusc or strace on your system. I don't know where they live on your box, so I'm making up a path: Code:
0 15 * 7 5 /usr/sbin/strace perl /path/nov.pl > /tmp/crontrace.txt Then at the command line do: Code:
/usr/sbin/strace perl /path/nov.pl > crontrace.txt grep for the word "open" and look for shared library names - in both logfiles. You may even be starting different versions of perl for all I know. Like /home/yogesh/perl vs /usr/local/contrib/bin/perl |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Executing a script through a cron job |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|