Files
Scripts/SynologyTimedShutdown.sh

28 lines
802 B
Bash

#!/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 borg | wc -l` -eq 1 ]; then
log "Triggering scheduled post-backup shutdown"
shutdown now
exit 0
else
log "Automatic shutdown cancelled due to concurrent backup task"
exit 2
fi
############################################################################