LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-26-2010, 09:32 AM   #1
sir-lancealot
Member
 
Registered: Aug 2007
Posts: 346

Rep: Reputation: 31
Starting down the bash road, rsync fail question


Actually I guess I could ask, if I have been using linux for 7+ years and wanting to automate more, do I look to bash or something like perl. A co-worker swears by it, but just a .02 to throw out, if one is really easier or better to learn!

So with that, I have a remote server which I want to backup nightly, and report that things went well. I have a website setup, mysql, and basically after the rsync is complete I will curl the site with the ID which resets the 'last checked in time'. A cron scipt checks all the watchdog's, and if one is in an alert stage, it will email/sms, etc. depending on the function.

So the
rsync -av root@thrasher:/mnt/emc/maintenance/backups/ForecastDB/* /var/share/backup/database/forecast

curl http://mymaintenancepage.php?wid=x (where x is the unique ID for that service). That part works fine, so I can check it in, see the time reset, etc. but if my bash script just has the rsync, then the curl, if rsync fails for some reason, does the bash script just continue to the next line and curl it?

If so, how do you change that, and if I have to do this with 5 servers, is it recommended to have 5 separate jobs or one in succession.

Thanks as I take on this new adventure
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 10-26-2010, 09:56 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
You can test whether the rsync was successful or not by putting it in an if/then conditional:

Code:
#!/bin/bash
if rsync -av root@thrasher:/mnt/emc/maintenance/backups/ForecastDB/* /var/share/backup/database/forecast
then curl http://mymaintenancepage.php?wid=x 
else echo "ERROR:  The rsync failed."
fi
That tells it to run the rsync and if successful run the curl. If not it will output an error message (to stdout - you can append >2 to the else line (after the quote) to make it output to stderr instead).

Perl is generally more efficient in execution than bash so many people writing big scripts will do it in perl. However, bash is useful for quick and dirty scripts and is used in many big scripts. Of course there are also things like Python, Ruby, PHP. You'll see people argue that one is better than another but it really comes down to personal opinions and those often are based solely on what the user first learned.
 
2 members found this post helpful.
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Starting and stopping rsync without loosing a lot of data bixbyr Linux - Networking 3 08-09-2011 02:32 PM
* starting network connection manager wicd [fail] vin_akleh Linux - Newbie 0 02-22-2010 09:54 PM
CentOS HALdaemon starting fail Actionscript3 Linux - Newbie 1 01-25-2010 12:47 PM
Wireless starting to fail - update driver? whammack Linux - Wireless Networking 4 05-03-2007 04:32 PM
RSYNC and BASH chris28 Linux - Networking 4 02-14-2006 04:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:20 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