"Commenting out an echo killed my bash script" - yes, really!
Here (with password amended!) is part of my bash script which takes a database snapshot from time to time - and it's been running well over a 24 hour cycle, giving me checkpoints to return to. But it was getting a bit verbose, so I added a simple # in front of the successful emailing ine.
/usr/local/mysql/bin/mysqldump -ufgw -psummathere -h127.0.0.1 fgw > /home/backups/$HOUR/fgw.sql
if [ "$?" -eq 0 ]; then
echo "Success $HOUR fgw" | mail -s "FGW good dump" graham@wellho.net
else
echo "Mysqldump encountered a problem $HOUR fgw" | mail -s "FGW BAD dump" graham@wellho.net
fi
My change got rid of the good backup message which had been "spamming" me during testing ... but it also got rid of the rest of my backup procedure. Oops. It turns out that you're not allowed an empty block in an if!
Advise is to refactor the script - or to add a null statement into the block if you want to retain the ability to uncomment the echo and start emailing again (or whatever your programmer-switchable action is!). Suitable null statements are
:
(yes, a sinle colon) or
echo nothing > /dev/null
but please note I have not yet tested these. I'm more concerned, as I write this, to be handcranking a backup and watching the backup pots refill with complete data sets!
(written 2015-01-19)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
A167 - Web Application Deployment - Shell Programming (bash) [63] Almost like old times - (2004-09-26)
[64] Shell Script for CGI on the web - (2004-09-26)
[749] Cottage industry or production line data handling methods - (2006-06-07)
[827] No news is good news with Unix and Linux - (2006-08-10)
[1287] Work and play at Well House Manor - Football and Shell Shortcuts - (2007-08-02)
[1345] Perl and Shell coding standards / costs of an IT project - (2007-09-11)
[1468] Lexical v Arithemetic testing, Bash and Perl - (2007-12-11)
[1527] Selecting file names in a shell - one word or another - (2008-02-02)
[1904] Ruby, Perl, Linux, MySQL - some training notes - (2008-11-23)
[3791] The Kernel, Shells and Daemons. Greek Gods in computing - (2012-07-01)
[4487] Starting MySQL. ERROR! The server quit without updating PID file - how we fixed it. - (2015-05-06)
[4584] Bash ... some new scripts to - handling user input - (2015-11-27)
[4586] Extending your bash shell with aliases, functions and extra commands - (2015-11-28)
[4587] shell - bash. Writing conditional tests and statements - the options available - (2015-11-28)
A162 - Web Application Deployment - Backups and File System Management [153] Linux - where to put swap space - (2004-12-16)
[334] Symbolic links and hard links - (2005-06-02)
[554] What backup is adequate? - (2006-01-04)
[593] Finding where the disc space has gone - (2006-02-06)
[703] Copying files and preserving ownership - (2006-04-28)
[735] Boys will be boys, saved by Ubuntu - (2006-05-27)
[754] tar, jar, war, ear, sar files - (2006-06-10)
[1013] Copy multiple files - confusing error message from cp - (2006-12-30)
[1023] Finding public writeable things on your linux file system - (2007-01-06)
[1288] Linux run states, shell special commands, and directory structures - (2007-08-03)
[1439] Linux / Unix - layout of operating system files - (2007-11-20)
[1648] The tourists guide to Linux - (2008-05-20)
[1765] Dialects of English and Unix - (2008-08-21)
[1801] Will your backups work if you have to restore them? - (2008-09-18)
[1893] Some Linux and Unix tips - (2008-11-18)
[2299] How much space does my directory take - Linux - (2009-07-20)
[4056] An overpractical test of our backup strategy! - (2013-03-30)
[4063] Backups by crossover between network centres - setting up automatic scp transfers - (2013-04-13)
[4115] More or less back - what happened to our server the other day - (2013-06-14)
[4390] Checking MySQL database backups have worked (not failed) - (2015-01-10)
[4405] Backup procedures - via backup server - (2015-01-24)
[4481] Extracting data from backups to restore selected rows from MySQL tables - (2015-05-01)
Some other Articles
Which (virtual) host was visited? Tuning Apache log files, and Python analysisThe unbalanced relationship between customer and providerFinding sum, minimum, maximum and average in Python (and Ruby)Selecting RECENT and POPULAR news and trends for your web site usersCommenting out an echo killed my bash backup scriptThe Campus in Melksham - name, logo, and livery choiceAccessing variables across subroutine boundaries - Perl, Python, Java and TclTransWilts / Press and Publicity report for AGM / 30th January 2015Java Utility class - flexible replacement for array. Also cacheing in objects and multiple catch clauses example.Preparing data through a little bit of Perl