Best way to start debugging a shell script is to run it with debugging switches like
Code:
/bin/bash -vx /path/script --any-args 2>&1 | tee /path/debug.log
That way you see variables populated, errors fly by and you can
Code:
less "/path/debug.log"
to read back if it went too fast.
As far as basics goes I would always ensure variables are quoted properly, there's nothing else in your script that could indicate a problem:
Code:
#!/bin/bash
set -evx
NOW=$(date +"%Y%m%d")
mysqldump -h server -u user -ppassword dbname | gzip > "/path/to/folder/db-quarter-backups/db-${NOW}.sql.gz"
exit 0
*As far as standards go I would suggest against using "%b-%d-%y-%H-%M". While the output may seem valid on its own, after you've got a gazillion of files to sort and search through it suddenly no longer applies. Easier would be "%Y%m%d" and if you expect to move backups off site (which you should) then you will want something like "${HOST}-${DATE}" or "${DOMAIN}-${HOST}-${DATE}".
Code:
function howto() { echo "Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html
http://www.gnu.org/software/bash/manual/html_node/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/
http://mywiki.wooledge.org/BashFAQ
http://mywiki.wooledge.org/BashPitfalls"; }