Wrong output when run via Cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Wrong output when run via Cron
# 1  
Old 10-29-2012
Wrong output when run via Cron

Hello,

This may be a simple one, but i can't see what the issue is.

When i run the script via CLI, then i get the correct output via the if statement, but when i run via CRON i get the wrong statement.

Code:
echo " Checking Job Status" >> $DIR/Bpimagecleanup_$DATE
JOB_STATUS=`/usr/openv/netbackup/bin/admincmd/bpdbjobs | grep -i image | awk 'NR==1{print $4}'`
echo " Finished Job Status" >> $DIR/Bpimagecleanup_$DATE

echo $JOB_STATUS >> $DIR/Bpimagecleanup_$DATE

if [[ $JOB_STATUS = "Done" ]];then
 echo "Bpimagecleanup Kicked off" >> $DIR/Bpimagecleanup_$DATE
 /usr/openv/netbackup/bin/admincmd/bpimage -cleanup -allclients
else
 echo "No action - Bpimage running!!!" >> $DIR/Bpimagecleanup_$DATE
fi

Code:
Output via CLI

 Checking Job Status
 Finished Job Status
Done
Bpimagecleanup Kicked off


Code:
Output via CRON

 Checking Job Status
 Finished Job Status
Done
No action - Bpimage running!!!


What is wrong in the statement, i have been looking at the code to long to notice the issue.

I should get "Bpimagecleanup Kicked off" as no job is running and the job status is done...

Thanks
# 2  
Old 10-29-2012
Code:
# this
if [[ $JOB_STATUS = "Done" ]];then
# should be ---   (notice the spaces.)
if [[ $JOB_STATUS = "Done" ]] ; then

If you do no specify the shell with a shebang ( Ex: #!/bin/ksh ) then the cron daemon uses /bin/sh. This may not be the same shell you use from the command line. Changing shells impacts lots of things. I'm guessing the syntax error is the problem.

Do you see anything in mailx (as the use who owns the crontab) about the job?
# 3  
Old 10-29-2012
I did try that before and i also tried it now and made no difference

also the script is running as following

#! /bin/ksh
set -x
#
#
#
# 4  
Old 10-29-2012
Can you source your .profile file in your CRON entry and retry?

Code:
* * * * * . .profile; <your script>


Last edited by Yoda; 10-29-2012 at 01:11 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Homework & Coursework Questions

When I run the script, the cursor starts on the wrong line?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: It's a shell script using a looping logic, trap, tput, if, while. Most of the scripts in this book aren't written... (2 Replies)
Discussion started by: ckleinholz
2 Replies

3. UNIX for Advanced & Expert Users

Script run by cron gives no output

Hi All, I have a script which checks the status of HP Smart Array & then emails me the output. The script run fine when executed manually but I receive no output when configured in a cron job. The script is below: hpacucli ctrl slot=3 show config | mail -s "ARRAY STATUS-`date`"... (6 Replies)
Discussion started by: coolatt
6 Replies

4. Shell Programming and Scripting

Who -u gives different output if run from cron than if run from terminal?

If I run 'who -u' interactively or from a script invoked through bash in a tty on my Ubuntu 12LTS box I get an output like this: testuser pts/0 Dec 9 02:32 . 2163 (host.xx.yy) running the same through cron I get: testuser pts/0 2012-12-09 02:32 00:05 2163... (2 Replies)
Discussion started by: latimer
2 Replies

5. UNIX for Dummies Questions & Answers

Cron job executed at wrong time

Dear *nix users. I'm on Mac OS 10.6 / Terminal and try to use crontab to schedule two scripts every 30 minutes and every 41 minutes. I followed the man instructions and created / installed a crontab file for the current user:crontab -e with the following content */30 * * * *... (4 Replies)
Discussion started by: moxnos
4 Replies

6. Shell Programming and Scripting

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 .. 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"... (8 Replies)
Discussion started by: nithinankam
8 Replies

7. Solaris

run a service via startup script (correct me if I am wrong)

Environment Solaris 9 I have configured the Solaris9 as NTP client in which Solaris9 is syncing the time with a windows2008 R2 Server which is runing fine. Now I want that the xntpd service should start at startup. I did this via a script. Kindly correct if I did any thing wrong: 1.)Made... (9 Replies)
Discussion started by: z_haseeb
9 Replies

8. 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

9. Solaris

wrong ELF class: ELFCLASS32 when trying to run ps as particular user

I get the following error when running /usr/bin/ps on Solaris 10 as a particular non-privileged user: ld.so.1: ps: fatal: /usr/dt/lib/libXm.so.3: wrong ELF class: ELFCLASS32 Killed However I can run /usr/bin/ps successfuly as root or as any other non-privileged user. What could it be about this... (5 Replies)
Discussion started by: aussieos
5 Replies

10. Shell Programming and Scripting

what is wrong with cron?

Hey, I have been fighting with this SIMPLE script for a while, and almost going to crazy!! what I am doing is just get the DNS name for an IP, then echo the result, under bash shell, I can do this using command line, without any problem, $ a=`/usr/sbin/dig +short -x 216.239.37.104` $... (1 Reply)
Discussion started by: fedora
1 Replies
Login or Register to Ask a Question