Operating System - HP-UX
1833877 Members
1840 Online
110063 Solutions
New Discussion

Scripts from cron does'nt execute.

 
SOLVED
Go to solution
Andreas D. Skjervold
Honored Contributor

Scripts from cron does'nt execute.

Hi
On a 64 bit hp-ux 11.00 the following occurs:

Running a script manually succeeds:
ksh>/path/script.sh

Entering the same script into crontab:
30 10 * * * /path/script.sh >/dev/null 2>&1

does'nt work.

In /var/adm/cron/log the entries:
>CMD:/path/script.sh >/dev/null 2>&1
>bico 2226 c Thu Feb 1 10:30:00 MET 2001

Other scripts succeeds with the following log entries:
>CMD:/path/test_script.sh >/dev/null 2>&1
>bico 2302 c Thu Feb 1 10:45:00 MET 2001
>bico 2302 c Thu Feb 1 10:45:01 MET 2001

What is wrong?

Whats the rc=1 entry in the log?

Andreas
Only by ignoring what everyone think is important, can you be aware of what everyone ignores!
6 REPLIES 6
Paula J Frazer-Campbell
Honored Contributor
Solution

Re: Scripts from cron does'nt execute.

Hi
A script from cron does not have the same environmental variables as running it from a login.

You must set in your script these variables - sh etc.

HTH
Paula
If you can spell SysAdmin then you is one - anon
Sandor Horvath_2
Valued Contributor

Re: Scripts from cron does'nt execute.

Hi !

I think rc=1 mean the process return code was 1.

regards, Saa
If no problem, don't fixed it.
Shannon Petry
Honored Contributor

Re: Scripts from cron does'nt execute.

First, take a look at /usr/lib/cron/cron.allow
Make sure the user trying to excecute is allowed entry. (as the job is scheduled this is probably not the problem)

Next make sure that your script is defined in cron as
30 10 * * * /full/path/to/binary/script.sh

Make sure the execute bit is set for the user running the script.

Lastly and most importantly is the internals of the script. Many times PATH is not set, and standard commands are executed without the full path.

If your lazy like me in your scripts define PATH and export for your external calls as well. If you are security minded, then use full paths to binaries.
I.E.
MYVAR=`/usr/bin/ps -ef|/usr/bin/grep top|/usr/bin/grep -v grep |/usr/bin/head -1|/usr/bin/awk '{print $2}'`
/bin/kill "$MYVAR"

You have to remember that your interactive shells have executable directories set, which will cause scripts to work, where in a raw shell (from at or cron) it will fail.

The easiest way to test this is by unsetting PATH(path in cshell) in ksh or sh and trying to execute your script.

Another thing I always recommend is to have your scripts LOG commands and actions. It is pretty easy to make a /tmp/myscript.log, remove it if it exists and then touch it. Pipe script output to /tmp/myscript.log.

This will tell you exactly what is going on. I.E grep not found, awk not found,etc...


Regards,
Shannon
Microsoft. When do you want a virus today?
Andrew Lartey
Advisor

Re: Scripts from cron does'nt execute.

Hate to say this , but is the script definately
executable (e.g. -rwx-r-x-r-x)

runing ksh scriptname will execute it even if
the permissions are wrong
Andreas D. Skjervold
Honored Contributor

Re: Scripts from cron does'nt execute.

Thanks everyone!

It turned out that an undefined enviroment variable was the cause..

Andreas
Only by ignoring what everyone think is important, can you be aware of what everyone ignores!
Jaimin Parikh
Frequent Advisor

Re: Scripts from cron does'nt execute.

Hi,

rc=1 entry means return code of the program.

-Jaimin Parikh
JAIMIN PARIKH : Share your knowledge and help those who need your help!!