Operating System - HP-UX
1830226 Members
1844 Online
109999 Solutions
New Discussion

running scripts in crontab

 
user_2001
New Member

running scripts in crontab

Hi

I am trying to run a script in crontab - when I execute the script on a command line it will work not probelm but when I schedule it in the crontab it will not work!

I have included in the script to set the enviroment but still it will not work !!

Any suggestions

#!/usr/bin/sh

HOME="/apps/program/core_bin"

# A short wrapper script to set the TERM variable for ret.
# the curses front end to ret dies when TERM="".

TERM=hpterm
export TERM

program -c ret_alive_check.cmd > /dev/null
...
17 REPLIES 17
Mark van Hassel
Respected Contributor

Re: running scripts in crontab

Hi,

It could be that you have to use the whole pathname.
What is the return code in /var/adm/cron/log ?
The surest sign that life exists elsewhere in the universe is that none of it has tried to contact us
Thierry Poels_1
Honored Contributor

Re: running scripts in crontab

hi,
jobs executed from the crontab have a very limited environment.
To solve your problem you can add the full path to "program", as Mark as already mentioned, or you could define your PATH in your script.
good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
harry d brown jr
Honored Contributor

Re: running scripts in crontab

Thierry hit this right on the head. You can either fully qualify your executable path names (as in /apps/program/core_bin/program -c ret_alive....), or add your "HOME" path to the "PATH" variable (export PATH=$PATH:/apps/program/core_bin).
Live Free or Die
Praveen Bezawada
Respected Contributor

Re: running scripts in crontab

Hi
This has to do with the environment setting.
Include all the environment setting present in .profile in your script.
Also check the cron logs in /var/adm/cron

...BPK...
user_2001
New Member

Re: running scripts in crontab

okay I have added all these details about the env into the script.

added line into crontab .. as so
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /apps/program/core_bin/ret -c /apps
/program/core_bin/alive1.sh

but still - it won't run for me !!

Help
...
harry d brown jr
Honored Contributor

Re: running scripts in crontab

When you run this from the command line, does it work, and does the permissions include Execute? Also, is this a root cron, or another user?

/apps/program/core_bin/ret -c /apps/program/core_bin/alive1.sh

Live Free or Die
Thierry Poels_1
Honored Contributor

Re: running scripts in crontab

hi again,
did you check the user's (root?) mail? Output from a cron job will be mail to the user, so you might find something usefull there.

How about "alive1.sh", this script might also need some environment variables like PATH, ...

regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Ravi_8
Honored Contributor

Re: running scripts in crontab

Hi,
set TERM=hp and not to hpterm
never give up
user_2001
New Member

Re: running scripts in crontab

this is now my crontab

0,5,10,15,20,25,30,35,40,45,50,55 * * * * * /apps/program/core_bin/ret-c /apps/program/core_bin/alive1.sh

this is now the script
#!/bin/sh -f

HOME=/home/program
PATH=/bin:/usr/sbin:/usr/bin:/sbin:/usr/bin/X11:/usr/local/bin:/usr/lbin:/usr/uc
b:/usr/lbin:/etc:/usr/lib:.:/oracle8/OraHome1/bin:/apps/program/core_bin:/apps/
program/aim_bin
LOGNAME=program
SHELL=/bin/csh
TERM=hp
export TERM


ret -c ret_alive_check1.cmd > /dev/null

Still will not work for me in crontab -- works fine at command line !!

Pulling my hair out at moment !!
...
harry d brown jr
Honored Contributor

Re: running scripts in crontab

Can you do a "whereis ret" to determine if there is another program called "ret" in your path. What does "ret" do?
Live Free or Die
user_2001
New Member

Re: running scripts in crontab

ret -- is a program that calls up a terminal -- like calling SAM up and then sends a message from within sam!!
...
Sachin Patel
Honored Contributor

Re: running scripts in crontab

Hi Colet,
Is ret a gui program?

Sachin
Is photography a hobby or another way to spend $
Mark van Hassel
Respected Contributor

Re: running scripts in crontab

You probably have to set the DISPLAY variable in your script.
The surest sign that life exists elsewhere in the universe is that none of it has tried to contact us
harry d brown jr
Honored Contributor

Re: running scripts in crontab

Sachin is probably right about the "DISPLAY" variable, but if not, try this:

From a root login capture your environment variables:

env > /tmp/root_env

From your crontab script, add a line like this:

env >/tmp/cron_env

Then do a "diff" and add any missing variables.
Live Free or Die
user_2001
New Member

Re: running scripts in crontab

No ret is not a gui program more like a command line menu options!!
...
Sachin Patel
Honored Contributor

Re: running scripts in crontab

Hi
use FQPN for your program rat. i.e if your executable rat is in /opt/rat/bin then in script use

/opt/rat/bin/rat -c ?????? > /dev/null


Sachin
Is photography a hobby or another way to spend $
Wodisch
Honored Contributor

Re: running scripts in crontab

Hello Colet,

if I read your script right, you are using the C-shell
from within it. Well, then it will perhaps try to be
"interactive" and that would need a "controlling
terminal" which will not be available if called from
"cron"... There is an option for the C-shell to NOT
start interactively, though, you might try that...

HTH,
Wodisch