Operating System - HP-UX
1834178 Members
2365 Online
110064 Solutions
New Discussion

cron script not work .. tried everything!!

 
someone_4
Honored Contributor

cron script not work .. tried everything!!

Hey everyone
I have attached a file with 3 ways I have tried to run a script for a 3rd party app from our software vendor. The app is called swmaint. The issue is that we can only run this command on our maintance window because it brings down our whole system.Let me break down what is going on per script.

Script1:
It works thoguh cron the command line and though remsh shell. And this is what we wanna do!!

script2:
works though command line. But not though cron.

script3:
works though command line but not though cron.

script4:
works though command line but not though cron

does anyone have any ideas?

12 REPLIES 12
someone_4
Honored Contributor

Re: cron script not work .. tried everything!!

Also is it safe to telnet to local host?

Richard
A. Clay Stephenson
Acclaimed Contributor

Re: cron script not work .. tried everything!!

Okay Richard, it appears that you have your PATH set. That is the most common error when using cron. However, I suspect that you missed the second most common error: not trapping for interactive commands in a non-interactive environment (i.e. cron). This explains why it works perfectly from the shell and not from cron. It is almost always a bad idea to source a .profile in a cron script. Most .profile's have terminal setup stuff like tabs and tset. This will hang when stdin or stdout is not a tty device.

Possible Fix 1)
surround everything that may be looking for a terminal with
if [ -t 0 -o -t 1 ]
then
terminal command here
fi

-t 0 (stdin) -t 1 (stdout)

Possible Fix 2 (better answer))
Have a config file which sets the stuff your need in a separate which must not have an exit statement. Then both your cron script and your .profile can source this file.

This still may not be enough. You may need to use an exec statement to redirect stdin, stdout, and/or stderr.
If it ain't broke, I can fix that.
Deepak Extross
Honored Contributor

Re: cron script not work .. tried everything!!

Richard,

You would be logged in as root when you submit the job to cron, right?

After cron triggers script 3, does the file /eteam/reconfig/reconf.log
contain "reconfig started" ?
someone_4
Honored Contributor

Re: cron script not work .. tried everything!!

Yes the log shows that it did start.

richard
Deepak Extross
Honored Contributor

Re: cron script not work .. tried everything!!

Could you try putting some more echo statements around the calls to swmaint, just to see where it is getting stuck?

Also, if you redirect the stdout & stderr to the same log file, it should be helpful. I'd hate to see a '/usr/sbin/ unreadable ' message in the logfile! :)
G. Vrijhoeven
Honored Contributor

Re: cron script not work .. tried everything!!

Hi Richard,

Put on some loggin and source your .profile (cd . ./home/username/.profile)
check out the results.

Gideon
Volker Borowski
Honored Contributor

Re: cron script not work .. tried everything!!

Richard,

check interactively, if your command works when TERM is not set (I had this with ADABAS D database tools).

Script 1 sets TERM !

Script 2 sets TERM, but excutes .profile afterwards, and maybe resets it (swap the lines and check) !

Script 3 and 4 do not set TERM !

That is the most obvious diffrence I found.

Hope this helps.
Volker
Satish Y
Trusted Contributor

Re: cron script not work .. tried everything!!

Hi Richard,

In all scripts don't set term variable, set it in /.profile only and execute . /.profile in all scripts. I feel it will work bcos as soon as u r executing . /.profile previous settings of TERM variable are resetting.

And also recheck ur cron entries.

Cheers...
Satish.
Difference between good and the best is only a little effort
Krishna Prasad
Trusted Contributor

Re: cron script not work .. tried everything!!

Does the script run as root? or another user?

Also it looks like some path settings need to be added to the script. Cron doesn't always source in .profile or .cshrc

Another thing could be that the scripts needs to write out to a device so maybe add > /dev/null or something like that.
Positive Results requires Positive Thinking
someone_4
Honored Contributor

Re: cron script not work .. tried everything!!

The script runs as root. What does the telnet do that the cron wont do?? I have no idea maybe this app only works a certain way.

Richard
Joseph C. Denman
Honored Contributor

Re: cron script not work .. tried everything!!

Hi Richard,

I suspect a env var is the cause. Try this:

I the script, redirect you environment to see what is different from the shell and the cron.

Something like

env > /tmp/script2_cron_env.txt

Then run it from the cron.

Then change it to read

env > /tmp/script2_shell_env.txt

Then run it from command line.

Look and see what the differences are????

I bet you will find your answer.


If you can run it from the command line, you can run it from the cron.

...jcd...
If I had only read the instructions first??
harry d brown jr
Honored Contributor

Re: cron script not work .. tried everything!!

Richard,

most definitely something in your environment is different from cron. Remember cron has a very limited number of environment variables set. full pathnames should always be used. Someone suggested doing a cron job to output what the "env" variables are, and then do an "env" in your login to see what the differences are, especially the PATH (order counts).

live free or die
harry
Live Free or Die