Update script for better error handling
All checks were successful
build-linode-img / build-linode-img (push) Successful in 2m29s

This commit is contained in:
iFargle 2023-12-16 17:33:07 +09:00
parent bab7a1cf97
commit 7e7502696a

View file

@ -9,9 +9,28 @@ GOTIFY_TOKEN=`cat /var/run/secrets/gotify_token | head -n 1`
payload="{\"message\": \"Backup has started\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: Backup Started\"}"
curl -X "POST" "https://gotify.sysctl.io/message" -H "accept: application/json" -H "Content-Type: application/json" -H "X-Gotify-Key: $GOTIFY_TOKEN" -d "$payload"
drive1=`lsblk -o NAME,SERIAL | grep -v crypt | grep 9RGHYP8C | awk {'print $1'}`
drive2=`lsblk -o NAME,SERIAL | grep -v crypt | grep 9RGXW93C | awk {'print $1'}`
drive3=`lsblk -o NAME,SERIAL | grep -v crypt | grep 5QH05G3F | awk {'print $1'}`
drive1=`lsblk -o NAME,SERIAL | grep -v luks | grep 9RGHYP8C | awk {'print $1'}`
drive2=`lsblk -o NAME,SERIAL | grep -v luks | grep 9RGXW93C | awk {'print $1'}`
drive3=`lsblk -o NAME,SERIAL | grep -v luks | grep 5QH05G3F | awk {'print $1'}`
mount1=`mount -l | grep $drive1`
mounted1=`echo $?`
mount2=`mount -l | grep $drive2`
mounted2=`echo $?`
mount3=`mount -l | grep $drive3`
mounted3=`echo $?`
echo "status"
echo "$drive1 / $mount1 / $mounted1"
echo "$drive2 / $mount2 / $mounted2"
echo "$drive3 / $mount3 / $mounted3"
# If any drive isn't found, exit:
if [[ $mounted1 != 0 ]] && [[ munted2 != 0 ]] && [[ $mounted3 != 0 ]] ; then
payload="{\"message\": \"Backup stopped. One or more local drives are not mounted.\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: Backup Stopped\"}"
curl -X "POST" "https://gotify.sysctl.io/message" -H "accept: application/json" -H "Content-Type: application/json" -H "X-Gotify-Key: $GOTIFY_TOKEN" -d "$payload"
fi
echo "Drive 1: $drive1"
echo "Drive 2: $drive2"