The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's manas6 UNIX for Dummies Questions & Answers 0 06-05-2008 03:44 AM
Return of EXIT status ( $? ) ZINGARO HP-UX 1 03-12-2008 04:07 AM
Verify scp return status new2ss Shell Programming and Scripting 2 06-28-2006 07:04 PM
return ftp status blt123 Shell Programming and Scripting 12 07-21-2005 02:48 AM
Return status... Shaz Shell Programming and Scripting 7 11-19-2002 03:35 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 06-01-2008
Registered User
 

Join Date: May 2008
Location: Hong Kong
Posts: 1
Terminal And Cron Job Return Different Status Code

Dear All,

I want to write a shell script to test the server is running or not. The method is pinging the server and examine the status code.

the script:

#/bin/tcsh

ping -c 3 host
if ($? != 0) then
actionA
endif

This script work fine in terminal. The status code is 0 when the host is running and 2 when the host is down.

But when I run the script in cron job, the status code is only returned in 1, no matter the host is up or down. Did I do something wrong in the script?

Thanks for your attention and help.
Reply With Quote
Forum Sponsor
  #2  
Old 06-01-2008
awk awk is offline
Registered User
 

Join Date: Feb 2007
Posts: 119
where is ping?

add an "echo $PATH" at the beginning of your script, make sure ping is in the path when run as a cron job.

Also, check your individual system and see what the default shell is when cron in running. Be explicit on your shell in the first line of the script with a "#!/usr/bin/sh"

Here's what I am thinking - if PATH isn't right, ping won't be found, returning an error code of 1.

if you are running some weird shell that is different than the interactive one, that also could cause the format for the if the be wrong.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:50 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0