LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-15-2016, 04:39 AM   #1
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Rep: Reputation: Disabled
return code to continue script or quit script and email


hi all,

i have made a script and it works well just i want to add to it

rsync -a "${fSaveDir}".tar /archived_projects/

new code goes here

rm -f "${fSaveDir}".tar

inbetween these two lines of code i want it to either continue the script if the last command returned a code 0 (aka successful) but if it returns any over number, quit the script and email

i know this is possible but i dont know how to implement it

sorry

thanks

rob
 
Old 04-15-2016, 05:19 AM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,683

Rep: Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713Reputation: 2713
Google is your friend. Man your servent.

Two things you may want to look up:
1. 'if' can be used to execute blocks of code depending upon the code return from a command, ie
Code:
if rsync command
then
   dostuff
else
   do other stuff
fi
works.
2. the environment is loaded with a value of the code return from the last run command. You can use this to test and run conditional code after the command exits. You will find this documented in your shell man pages.


You should be able to google for bash tricks and find both of these mentioned on the internet.
 
Old 04-16-2016, 08:31 PM   #3
cnamejj
Member
 
Registered: Mar 2015
Distribution: Ubuntu
Posts: 37

Rep: Reputation: Disabled
You can also add a check like this if you want.

Code:
if [ $? -ne 0 ]
then
   ...whatever you want to do after an error...
fi
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
dpkg return error :post installation script return an error code (1) grimfold Debian 2 09-10-2009 01:55 PM
Bash script: return code ftp TalkingMarble Linux - Newbie 3 05-09-2008 09:37 AM
Start a script after GDM autologin, don't quit when script finishes Plastech Linux - Newbie 2 05-29-2007 10:15 AM
Return code of a shell script zachos.v Linux - Software 3 10-10-2006 09:51 AM
return value from shell script to c code? khucinx Programming 1 05-13-2004 03:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration