Operating System - HP-UX
1838108 Members
3280 Online
110124 Solutions
New Discussion

Re: Output of job run from cron

 

Output of job run from cron

Hi,
I have made a shell that's suppposed to run everyday at 24.00hrs and search all files with s-bits set. If I run the shell from prompt it excutes correctly and the listing of found files are directed to a file. When I am calling the same shell through cron the shell executes at 24.00 hrs but there is no output in the directed file.

Do i have mention the output file in the cron itself ?
what if i have different output files that are used as input files ?

the enrty in my crontab is
0 0 * * * /mnb/admin/find_sbit.sh
the log shows
CMD: /mnb/admin/find_sbit.sh
root 10858 c Mon Apr 23 00:00:00 IST 2001

how should I go about it ?

bye

7 REPLIES 7
Charles McCary
Valued Contributor

Re: Output of job run from cron

0 0 * * * /mnb/admin/find_sbit.sh > /tmp/OUTPUT 2>&1

should fix your problem.


Mike Hassell
Respected Contributor

Re: Output of job run from cron

Prosanjit,

When shell scripts are run from cron, they default using the /bin/sh shell. This may be an issue depending on how your script was created. When you run the script from the shell do you run it like this:

/mnb/admin/find_sbit.sh

or

/mnb/admin/find_sbit.sh > sbit.out

If you run it from command line and redirect the output to a file, then you will have to do the same in cron, such as:

0 0 * * * /mnb/admin/find_sbit.sh > sbit.out

If this is not the case, ensure that whatever shell you use for your testing is in the header of the script, ex.:

#!/bin/ksh

So cron does not automatically run it with /bin/sh. Let me know if this helps or not, an example of your script would help in determining what is going on. Good luck.

- Mike
The network is the computer, yeah I stole it from Sun, so what?
Andrew Maslin
Frequent Advisor

Re: Output of job run from cron

Another thing to remember is that the environmental variables are not all the same when running a script through cron as they are for an actual login. For example, if you have the output automatically sent to a file and use an environmental variable to determine the path or filename, it may not have the information it needs when run in the cron. I don't remember what variables specifically are or are not loaded in the cron, but you might make sure you explicitely name files and paths whenever possible.
Philip Chan_1
Respected Contributor

Re: Output of job run from cron

Hi,

You'll have to specify the output file in your cron entry

eg. 0 0 * * * your_cron > your_cron.out 2>&1

note for the "2>&1", that would re-direct all standard errors to standard out as well, this way you can see every output message that came out from your job.

If you DON'T specify an output file in your cron job, you should still be able to see the outputs in your emails because the cron daemon would do you this flavour.

I'm not sure if I catch your second question correctly but I'll give it a try. "Input" parameters are usually constant, unless you entered a command expression on this. You can re-write your cron entry as,

0 0 * * * your_cron > ``.out 2>&1

Be careful if involves the date command, for every "%" sign you should precede it by a "\".

Hope this help.

Regards,
Philip
Paula J Frazer-Campbell
Honored Contributor

Re: Output of job run from cron

Hi

Also change the cron time to either 23:59 or 00:01 hours as the time of 00:00 could be causing a problem (zero hours and zero mins).


Paula
If you can spell SysAdmin then you is one - anon
Vincenzo Restuccia
Honored Contributor

Re: Output of job run from cron

Edit in find_sbit.sh set -x and
0 0 * * * /mnb/admin/find_sbit.sh > /tmp/OUTPUT 2>&1

f. halili
Trusted Contributor

Re: Output of job run from cron

Try the ff below:

0 0 * * * /mnb/admin/find_sbit.sh > mylog 2>&1

this will send the standard output & std err to mylog


- fnhalili
derekh