pl script in crontab

Hi
I have successfukky created a sh script that runs perfectly well when run. It contains within a pl script that when run through a crontab will not run. Are there restrictions running a pl in cron?

No. If the script will run from the command line, it will run in cron.

1 Like

so something else is preventing it run in cron??

You may need to reload a proper environment when using cron (there is a bunch of thread about it around here)

It could be your environment or it could be the script. Try running it in cron with out redirection. In other words, remove any "> /dev/null 2>&1" in the crontab entry.

Also, I am not familiar with Perl, but is there a switch you can put in the first line of the script that will show each line as it is executed? I am thinking of something similar to "-x" in Korn Shell.

1 Like

Thanks Bluescreen
I removed the redirect to no affect. The perl script within the sh script runs fine from command line. The issue arises when it�s cron�ed. Incidentally I have several other scripts cron�ed running ok.

With the redirect removed, any error messages or program output should be in unix mail for the owner of the cron.
Is this a "root" cron?
If you find error messages, please post the error messages.

The basic cron log will contain a record of whether the job ran and whether it worked (rc=0) or failed (rc=n).

Please post the line(s) from crontab and the program itself, making it clear who owns the crontab and which user is normally used to run the script.

1 Like

Thanks methyl

Unfortunatel y I do not have root to this server but ovioulsy have rights to run cron under my profile.
How do I locate cron records?

That's somewhat optimistic. There are plenty of reasons for a script that runs fine on the command line to fail in cron if not modified. Some of them are:

  • an improperly set PATH. Any script run through cron that use commands located outside of /bin, /usr/bin should have its PATH set inside it.
  • other required environment variables unset. The user's dot files like .profile are not read by cron.
  • resources required unavailable (eg. an X11 server)
  • A tty expected, cron jobs aren't connected to a terminal.

Initial script only had path #!/usr/bin/sh and does refer to a .pl script.
I have amedned now to have two paths with

#!/usr/bin/sh [At the start as normal]

&

#!/usr/bin/perl -w [before perl script is run]

This had no affect and the cron still does not run the script..

There is more information in the parallel post from the same original poster.
http://www.unix.com/shell-programming-scripting/156715-crontab-running-pl-script-2.html

Is the /usr/bin/sh script calling the /usr/bin/perl script? -OR- is the Perl script embedded in the sh script? If you can run this from the command line and it completes normally, do you have something in your environment (/usr/bin/env) that is not included in your sh script? Check you PATH var and any other vars that are in your environment and not in your sh script.

HTH

1 Like

Many thanks bluescreen. How do I check my scipts env?

---------- Post updated at 03:18 AM ---------- Previous update was at 03:13 AM ----------

My env is as such

alps$ env
TERM=xterm
SHELL=/bin/sh
SSH_CLIENT=172.21.20.206 51860 22
OLDPWD=/home/it/capopt
SSH_TTY=/dev/pts/2
USER=capopt
LD_LIBRARY_PATH=/usr/local/lib:/usr/local/ssl/lib:/usr/local/mysql/lib:/usr/local/mrtg-2/lib:/usr/local/mrtg-2/lib:/usr/share/lib:/usr/openwin/lib:/usr/openwin/platform/sun4u/server/lib:/usr/sadm/lib/smc/lib:/usr/local/lib:/etc/lib:/etc/security/lib:/lib:/opt/SUNWits/Graphics-sw/xil/lib:/usr/sadm/smc/lib:/usr/sadm/lib:/usr/ccs/lib:/usr/openwin/platform/sun4u/server/lib:/oracle_install/product/10.2.0/lib32:/usr/sfw/lib
ORACLE_BASE=/oracle_install
PATH=/usr/bin:
MAIL=/var/mail//capopt
PWD=/home/it/capopt/APNRD/S30
EDITOR=vi
TZ=Eire
ORACLE_TERM=vt100
PS1=alps$
SHLVL=1
HOME=/home/it/capopt
LOGNAME=capopt
VISUAL=vi
SSH_CONNECTION=172.21.20.206 51860 192.168.198.110 22
ORACLE_HOME=/oracle_install/product/10.2.0
_=/usr/bin/env

---------- Post updated at 04:12 AM ---------- Previous update was at 03:18 AM ----------

I think my crons env is as follows as I enabled set >/tmp/mycronenv

alps$ more mycronenv
HOME=/home/it/capopt
IFS=

LOGNAME=capopt
MAILCHECK=600
OPTIND=1
PATH=/usr/bin:
SHELL=/usr/bin/sh
TZ=Eire

---------- Post updated at 04:56 AM ---------- Previous update was at 04:12 AM ----------

Hi again

i have now incorpotrated all my env vars into the script and through cron it now runs :slight_smile: :slight_smile: :).
What Im not sure about is which vars are actually required to run the script. Do I actually need all of them in there??

Think about what resources your script actually needs to run. I'm sure the PATH (which is the same in both) and LD_LIBRARY_PATH var are probable required. What about the Oracle vars? Does the script need them too? It will just take a bit experimenting by removing some to see of the script runs with out them. If it does, them remove a few more and try it again. Keep doing this until your script will not run if you remove one var. Then you know you've got it! :smiley:

1 Like

Thanks Bluescreen for your help with this problem. It is very much appreciated.

---------- Post updated at 08:44 AM ---------- Previous update was at 05:37 AM ----------

Thanks to all participants who attempted and did assist me in this thread