The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 06:44 AM
Return of EXIT status ( $? ) ZINGARO HP-UX 1 03-12-2008 07:07 AM
Verify scp return status new2ss Shell Programming and Scripting 2 06-28-2006 10:04 PM
return ftp status blt123 Shell Programming and Scripting 12 07-21-2005 05:48 AM
Return status... Shaz Shell Programming and Scripting 7 11-19-2002 06:35 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-01-2008
isaac_ho isaac_ho is offline
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.
  #2 (permalink)  
Old 06-02-2008
awk awk is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0