I get a different output when i manually run the .sh script and when it is run by a cron job. Please help me ..
TMP1="/lhome/bbuser/script/wslog/sar.t1"
TMP2="/lhome/bbuser/script/wslog/sar.t2"
TMP3="/lhome/bbuser/script/wslog/sar.t3"
OUTPUT="/lhome/bbuser/script/wslog/sar.out"
SERVER=`uname -a | awk -F"." '{print $1}' | awk -F" " '{print $2}'`
date +"%m/%d/%Y" > $TMP1
sar | tail -3 | head -1 > $TMP2
awk '{FS= "\t"}{print $1 " " $4 " " $6 " " $7 " " $9}' $TMP2 > $TMP3
paste $TMP1 $TMP3 > $OUTPUT
scp $OUTPUT admin@xxxxx.edu:/apps/feed/dash/learn/sar$SERVER
cronjob syntax
* * * * * cd /lhome/bbuser/script/wslog; ./appsar.sh > out 2>&1
when i run it manually i get the below output
12/03/2012 04:40:01 8.67 1.24 0.11 89.99
when the cron job runs it i get the below output
12/03/2012 16:40:01 0.00 0.11 0.00
```[/b]
[/CODE]
I dont understand the problem.
Please help!
RudiC
December 3, 2012, 6:01pm
2
Use code tags.
Search these forums for the differences between interactive and cron execution.
Add a 'set -x' into the script to see what it's doing...
I suspect the code below.
sar | tail -3 | head -1 > $TMP2
You need to check $TMP2 with the following command which need to be in the script.
cat $TMP2 > /tmp/tmp2.output
You will figrue out why the outputs are different.
Cheers,
When I execute it manually I am getting it right, how do i check wts happening in when the cron runs???
This question is so common it's in our FAQ.
Make sure you have a proper PATH set. cron gets a minimal PATH and probably can't find all your commands. You can do . /etc/profile
at the top of your script, or set PATH manually yourself.
Minimal path???
I am using the same user with which the cron runs it... I am getting a different output!
Could you please provide me the link to FAQs.
---------- Post updated at 01:30 PM ---------- Previous update was at 01:27 PM ----------
Could you please let me know how to check the log of a cron job???
Is their any way to check that??
Scott
December 4, 2012, 12:36pm
8
There is a link to our FAQ area in the blue menu bar at the top of every page.
Doesn't matter who's account the cronjob is from. Cron has only a minimal environment. You need to make sure the ENV is set for cron as well.
I believe I also see time differences.
The cron log will typically be found in /var/log - this depends on the OS and distro.
To see what happens when cron executes, on the line of your cronjob, you could put the following at the end of the command and create a log file.
00 01 * * * myjob 2>&1 >> $LOG
STDOUT and STDERR are redirected to the $LOG
If you have some 'echos' in your script