SynologyTimedShutdown.sh

This commit is contained in:
2024-06-13 21:16:46 +01:00
parent 14e0cc4891
commit 52a3aa179e
+27
View File
@@ -0,0 +1,27 @@
#!/bin/bash
LOGFILE="/var/log/synology_timedshutdown.log"
touch $LOGFILE
# Log file #################################################################
log () {
TIMEDATE=$(date +%Y/%m/%d_%H:%M:%S)
echo "$TIMEDATE $1" >> $LOGFILE
}
if [ `cat $LOGFILE | wc -l` -ge 100 ]; then
>$LOGFILE
log "Log file was rotated"
fi
############################################################################
# Main loop ################################################################
if [ `ps -ef | grep borgmatic | wc -l` > 1 ]; then
log "Triggering scheduled post-backup shutdown"
shutdown now
exit 1
else
log "Automatic shutdown cancelled due to concurrent backup task"
exit 2
fi
############################################################################