Files
Scripts/ProxmoxTimedShutdown.sh
Dunestorm f31df4f2ca [Proxmox Timed Shutdown]
- Changed main loop to only retry twice after a 30 min interval.
2023-02-26 14:54:01 +00:00

36 lines
1.0 KiB
Bash

#!/bin/bash
LOGFILE="/var/log/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
############################################################################
log "Waiting 1hr to allow user to cancel shutdown"
sleep 1h
# Main loop ################################################################
for i in 1 2
do
if [ `ps -ef | grep vzdump | wc -l` -eq 1 ]; then
log "Triggering scheduled post-backup shutdown"
/usr/sbin/shutdown -h now
exit 1
else
log "Automatic shutdown delayed due to concurrent backup task"
sleep 30m
fi
done
log "Automatic shutdown cancelled due to concurrent backup task"
exit 2
############################################################################