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
rm & mv command failed due to too many files. videsh77 UNIX for Advanced & Expert Users 9 05-16-2008 03:01 PM
Problem with Mail command: exec failed. errno=2. hawkman2k UNIX for Dummies Questions & Answers 1 04-29-2008 10:50 AM
Fatal error: Command failed for target `build_crypto' sayed_021 SUN Solaris 1 02-13-2008 12:16 PM
Failed to get value from a file using sed command nir_s Shell Programming and Scripting 2 03-11-2006 05:53 PM
Solaris 9: make: Fatal error:Command failed for target eldiego UNIX for Dummies Questions & Answers 2 10-28-2005 04:11 PM

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 07-16-2008
trey85stang trey85stang is offline
Registered User
  
 

Join Date: May 2008
Posts: 70
Rerunning a command in a script that failed?

I have a script that occasionally has a command here and there that fails and I would like to set my script up to just re run the command if the exit code is 1.

Is there a simple way to do that without if/thens or redirecting to the command again?
  #2 (permalink)  
Old 07-16-2008
FunibonE FunibonE is offline
Registered User
  
 

Join Date: Jul 2008
Location: Silicon Forest
Posts: 16
How would you know if your script failed or not without testing? you can always manually run it
  #3 (permalink)  
Old 07-18-2008
trey85stang trey85stang is offline
Registered User
  
 

Join Date: May 2008
Posts: 70
Quote:
Originally Posted by FunibonE View Post
How would you know if your script failed or not without testing? you can always manually run it
files will be missing if a specific command fails - I get emailed the files thats how I know. its a reporting script and the apps reporting command sometimes just randomly fails for no reason what so ever... It would be great if there was an easy way to just rerun that one failed command.

I guess I will be a big boy and add in flow control for those commands failing
  #4 (permalink)  
Old 07-16-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
You COULD:

until [ $status == 0 ]
do
somecommand someargs
status=$?
done

echo "Exited with status:$status"



but it would loop indefinitely if the command always failed. Would probabally want to put some limit to the number of times to retry.
  #5 (permalink)  
Old 07-18-2008
trey85stang trey85stang is offline
Registered User
  
 

Join Date: May 2008
Posts: 70
Quote:
Originally Posted by Ikon View Post
You COULD:

until [ $status == 0 ]
do
somecommand someargs
status=$?
done

echo "Exited with status:$status"



but it would loop indefinitely if the command always failed. Would probabally want to put some limit to the number of times to retry.
Ill give this a try, Ill need to test it in my environment, this report is kind of heavy on the system so I will defiantly only need to make sure it runs 2x at the most
  #6 (permalink)  
Old 07-17-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,763
This is really not a great shell coding best practice but
Code:
somecommand arg1 || somecommand arg1
executes somecommand1 an additional time if it fails the first time.

This will NOT work with pipes i.e., command1 | command2 because the status returned is from the rightmost element in the line, but others may fail. Some implementations have a workaround for this problem.
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 02:40 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