LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 04-27-2016, 12:50 AM   #31
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726

If you start your script with "#!/bin/sh -e" or "#!/bin/bash -e" then any time it gets to a command that fails, the script will stop working unless you provide an alternative action. Stopping the script is better than going ahead and copying to a directory instead of a mounted partition, for example.

Consider the following segment and what it would do if mount fails:

Code:
mount -t cifs //serverip/sharedir/ /backup/dir1 -o credentials=/credentialslocation
#this mounts the entire shared drive using a root read only credentials file
sleep 10s

rsync -avz /backup/dir1/ /backup/dir2
#backs up the data from dir1 to dir2
sleep 10s
If mount fails, then rsync will still go ahead and copy 'nothing' to the destination directory. From there the script will continue forward as if everything were ok and you won't get your data backed up, even though the script says it did.

But if the script started sh or bash with the -e option, it would stop after the failed mount and never get to the rsync or anything else. The exit code for the script would be that of an error and could be used to trigger some action like an e-mail or some other notification.

The program true always succeeds and provides an exit code saying it succeeded. The program fail always fails and provides an exit code saying it failed. So consider the following script:

Code:
#!/bin/sh -e

true
date
false
date
true
date
Will it print the date once, twice, or thrice? What happens if you change the false to a true or vice versa?
 
  


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
Looking for Open Source SAN or LUN Backup Solution DukeLeto Linux - Software 4 04-22-2011 01:05 PM
Open Source File Replication/backup solution needed jeveretts Linux - Newbie 5 06-06-2010 11:19 AM
Open source backup solution ShaqDiesel Linux - Newbie 3 08-30-2008 03:53 PM
Open Source Backup Solution? jedimastermopar Linux - Server 8 06-03-2008 06:42 AM
LXer: Set up a MySQL backup solution in 15 minutes! (all using open source bits) LXer Syndicated Linux News 1 10-30-2006 04:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 12:51 AM.

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