Operating System - HP-UX
1748185 Members
4069 Online
108759 Solutions
New Discussion юеВ

Re: Program can not be run in the cron environment

 
SOLVED
Go to solution
arking1981
Frequent Advisor

Program can not be run in the cron environment

Dear everyone,

I don't understand why this happens.
I have a script with a commnand called dmcutil, a binary developped by us. I can run it mannually, no problem.

But when I want to run it periodically, I added the script into the cron job. What astonished me is the dmcutil never runs when the script was designed as a cron job.

I tried to put the command directly into cron enties like:
crontab -e

...
5 * * * * dmcutil >> /tmp/test.log
...

It was never invoked.
I don't what happens. Can anyone light me up? It will be appreciated.

Best Regards
Kang
Hello world...
23 REPLIES 23
arking1981
Frequent Advisor

Re: Program can not be run in the cron environment

I want to add more information.

Part of the scripts can be run in cron environment, only the command dmcutil can not be run.

The system and the binary:
s7dmc # uname -a
HP-UX s7dmc B.11.11 U 9000/800 3617756966 unlimited-user license
You have mail in /var/mail/root


s7dmc # file /opt/dmc/bin/dmcutil
/opt/dmc/bin/dmcutil: ELF-64 executable object file - PA-RISC 2.0 (LP64)


Thanks
Kang
Hello world...
arking1981
Frequent Advisor

Re: Program can not be run in the cron environment

sorry not to compose all the information in one message. Here below is the results in /var/adm/cron/log

> CMD: /opt/dmc/bin/dmcManage.sh
> biadmin 2163 c Tue Oct 19 01:25:00 WAT 2010

Seeming no error for executing this cronjob.

Thanks
Xie Kang
Hello world...
TTr
Honored Contributor

Re: Program can not be run in the cron environment

What does the dmcutil do as far as tty i/o?
Aneesh Mohan
Honored Contributor

Re: Program can not be run in the cron environment


Try with complete path.

5 * * * * /opt/dmc/bin/dmcutil >> /tmp/test.log

Aneesh
arking1981
Frequent Advisor

Re: Program can not be run in the cron environment

Dear,

What do you exactly mean?
dmcutil is a bindary developped by us to manage a software. what do you mean tty i/o?

Thanks
Hello world...
James R. Ferguson
Acclaimed Contributor

Re: Program can not be run in the cron environment

Hi Kang:

> what do you mean tty i/o?

TTr is asking if your executable uses the terminal to do I/O. If you attempt to read from STDIN (file descriptor 0 which is normally the initiating terminal), then under 'cron' unless you have redirected from a file, no terminal exists and the crontask fails.

You might try something like:

5 * * * * dmcutil < /dev/null >> /tmp/test.log

Regards!

...JRF...
arking1981
Frequent Advisor

Re: Program can not be run in the cron environment

Re: Try with complete path.

5 * * * * /opt/dmc/bin/dmcutil >> /tmp/test.log

Aneesh

Dear Aneesh,
I tried your suggestion before, no effect.
1,2,3,4,5,10,12,13,14,15,16,19,17,18,35,40,45,50,52,53,55 * * * * /opt/dmc/bin/dmcutil >> /tmp/xk/tdmc.log
And an error with rc=137 was reported
> CMD: /opt/dmc/bin/dmcutil >> /tmp/xk/tdmc.log #/tmp/xk/ttDMCUtil
> biadmin 1141 c Sun Oct 24 14:52:00 WAT 2010
< biadmin 1141 c Sun Oct 24 14:52:01 WAT 2010 rc=137



I think there is not too much difference. As you can find the complete path is recorded in the cron/log:
> CMD: /opt/dmc/bin/dmcManage.sh
> biadmin 2163 c Tue Oct 19 01:25:00 WAT 2010
dmcutil is invoked by dmcManage.sh. However, there is a little difference, when executed in the above script, no rc=137 was reported.

Thanks
Kang
Hello world...
SoorajCleris
Honored Contributor

Re: Program can not be run in the cron environment

Hi Kang,

I have seen scripts fails when it runs as cronjob, but it runs in command line.

The only problem is the environement.
could you please export the environement in the job and check the change?

regards,
Sooraj
"UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity" - Dennis Ritchie
Bill Hassell
Honored Contributor

Re: Program can not be run in the cron environment

Your script works from an interactive shell because you have a customized environment. cron does NOT have this environment. All scripts that will be run in cron or batch or at must have everything defined, things like $PATH and other application environment variables. To see all the errors, turn on tracing in your script:

#!/usr/bin/sh
set -x

NOTE: the first line of all your script must start with the interpreter line so the correct shell will be run. This must be line 1 in your script. Then test the script using at:

/opt/dmc/bin/dmcManage.sh 2>&1 | at


Bill Hassell, sysadmin