Subj : Backup script tuning To : All From : paulie420 Date : Thu Sep 15 2022 16:01:03 I know I need to get [a lot] better at bash scripting, but I'm trying to learn how to go from green level just up a notch, first. :P I'm using rsync to backup external HDDs to another HDD, and writing results info to a backup_info.txt file after rsync runs. The first iteration just wrote 'successfully completed' blah blah blah - but I wanted to add in checking the rsync error codes and write either 'success' or 'this was the error code' and here's what I came up with in my first attempt at checking exit codes. Do things l00k right? ----- paulie420@pbs:~$ cat backup.sh #!/bin/bash #Backup 3 external HDDs to 16TB Drive retVal=$? rsync -av --delete /mnt/Beers4TB/ /mnt/datastore/PBS_backup/Beers4TB if [ retVal -ne 0 ]; then echo "There was an rsync error backing up Beers4TB:" >> ~/backup_info.txt echo $retVal >> ~/backup_info.txt else echo $(date) >> ~/backup_info.txt echo "/mnt/Beers4TB -> /mnt/datastore/PBS_Backup/Beers4TB COMPLETE!" >> ~/backup_info.txt fi rsync -av --delete /mnt/Backup4TB/ /mnt/datastore/PBS_backup/Backup4TB if [ retVal -ne 0 ]; then echo "There was an rsync error backing up Backup4TB:" >> ~/backup_info.txt echo $retVal >> ~/backup_info.txt else echo $(date) >> ~/backup_info.txt echo "/mnt/Backup4TB -> /mnt/datastore/PBS_Backup/Backup4TB COMPLETE!" >> ~/backup_info.txt fi rsync -av --delete /mnt/Backup6TB/ /mnt/datastore/PBS_backup/Backup6TB if [ retVal -ne 0 ]; then echo "There was an rsync error backing up Backup6TB:" >> ~/backup_info.txt echo $retVal >> ~/backup_info.txt else echo $(date) >> ~/backup_info.txt echo "/mnt/Backup6TB -> /mnt/datastore/PBS_Backup/Backup6TB COMPLETE!" >> ~/backup_info.txt fi exit $retVal ----- |07p|15AULIE|1142|07o |08......... --- Mystic BBS v1.12 A48 2022/07/15 (Linux/64) * Origin: 2o fOr beeRS bbs>>>20ForBeers.com:1337 (1337:3/129) .