Output differs when run manually and when cron job executes it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Output differs when run manually and when cron job executes it
# 1  
Old 12-03-2012
Output differs when run manually and when cron job executes it

I get a different output when i manually run the .sh script and when it is run by a cron job. Please help me ..


Code:
Code:
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
Code:
* * * * * cd /lhome/bbuser/script/wslog; ./appsar.sh > out 2>&1
when i run it manually i get the below output
Code:
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
Code:
12/03/2012	16:40:01  0.00 0.11 0.00


I dont understand the problem.
Please help!

Moderator's Comments:
Mod Comment Use code tags. See your PMs for a guide.

Last edited by nithinankam; 12-04-2012 at 12:23 PM.. Reason: code tags
# 2  
Old 12-03-2012
Use code tags.
Search these forums for the differences between interactive and cron execution.
# 3  
Old 12-03-2012
Add a 'set -x' into the script to see what it's doing...
# 4  
Old 12-03-2012
I suspect the code below.
Code:
sar | tail -3 | head -1 > $TMP2

You need to check $TMP2 with the following command which need to be in the script.
Code:
cat $TMP2 > /tmp/tmp2.output

You will figrue out why the outputs are different.

Cheers,
# 5  
Old 12-04-2012
When I execute it manually I am getting it right, how do i check wts happening in when the cron runs???
# 6  
Old 12-04-2012
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.
# 7  
Old 12-04-2012
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??
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script has different ouput via cron vs when run Manually

Hello Lads, I deployed a script on my mac to start and stop EC2 instances on AWS console. The script when started manually on the terminal does the expected stop and start. Problem is when i try to schedule it on a cron, it fails to recognize the AWS Keys which i set up as ENV variable by... (2 Replies)
Discussion started by: Irishboy24
2 Replies

2. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

3. Shell Programming and Scripting

Why my git command has no output in crontab but works well run this script manually?

cat /home/lyang001/update.sh #!/bin/sh #shopt -s expand_aliases HOME_DIR=/home/lyang001/updates UPDATE_MAIL=${HOME_DIR}/updates.mail rm $UPDATE_MAIL -rf cd $HOME_DIR/wr-kernel git log --no-merges --since="20 day ago" --name-status --pretty=format:"%an %h %s %cd" origin/WRLINUX_5_0_1_HEAD >>... (2 Replies)
Discussion started by: yanglei_fage
2 Replies

4. Shell Programming and Scripting

Shell script not getting called through cron job but executes fine manually.

Hi, My shell script not getting called through cron job. The same works fine when executed manually. I tried to generate logs to find if the scripts has some errors related to path using following command- trying to execute .sh file every 5 mins: */5 * * * * /home/myfolder/abc.sh... (17 Replies)
Discussion started by: Dejavu20
17 Replies

5. AIX

Script not getting executed via cron but executes when executed manually.

Hi Script not getting executed via cron but executes successfully when executed manually. Please assist cbspsap01(appuser) /app/scripts > cat restart.sh #!/bin/ksh cd /app/bin date >>logfile.out echo "Restart has been started....." >>logfile.out date >>logfile.out initfnsw -y restart... (3 Replies)
Discussion started by: samsungsamsung
3 Replies

6. Shell Programming and Scripting

how to run a script using cron job and send the output as attachment via e-mail using unix

how to run a script using cron job and send the output as attachment via e-mail using unix. please help me. how my cron job entry should be? As of now my cron job entry is to run the script at specific time, 15 03 * * * /path/sample.sh | mail -s "Logs" email_id In the above entry, what... (8 Replies)
Discussion started by: vidhyaS
8 Replies

7. Shell Programming and Scripting

Script behaves different when run from cron vs. manually

Hey all, Just wanted to get some input on a script I am using to import files into a MySQL database. The process is pretty simple: my main server exports these files and FTPs them. I have a script that FTPs them to the machine running that runs this script. The FTP script runs without issue... (2 Replies)
Discussion started by: billtwild
2 Replies

8. Shell Programming and Scripting

Does not run via cron job

I have a perl script, when I ran manually it works perfect. I check the permissions which are fine. How can I find out why it is not running? how can I setup a log to check. I am running it on solaris 9. It compares multiple files, SCP and then send out an e-mail. As I said when I ran it... (2 Replies)
Discussion started by: amir07
2 Replies

9. Solaris

SFTP errorcode 1 when run on cron but runs manually

I am trying to run a sript on cron to SFTP data to a company. Private and public keys are set up. When I run this manully it works fine, however it was failing when run on cron. I have narrowed down the problem - it fails at the code that says if the error code is 0 then continue . . . I... (2 Replies)
Discussion started by: Heidi.Ebbs
2 Replies

10. Shell Programming and Scripting

Can run script Manually, but not through Cron?

Hi all, I have a main script (called OracleCleanup) that runs some sql queries. that runs off a wrapper script which contains the sources for the login information and and JOB_HOME (the script is below). When I schedule this job in the cron the log says that it cannot open my list file, which... (4 Replies)
Discussion started by: MadHatter
4 Replies
Login or Register to Ask a Question