This one does what it says on the tin: Shut down the backup server when there are no more tasks running.
At first, I wanted to implement this as explained in this Proxmox forum tutorial. However, the hook scripts require SSH access from the PVE node to the backup server. I didn’t like this approach because I want to keep the backup server as separate as possible. So I went with polling the job list on the backup server itself instead.
The script
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#!/bin/bash # idle-shutdown.sh V1 # LUANI.de 09/2025 # count all tasks, zfs scrubs, online users, ... taskcount=$(/usr/sbin/proxmox-backup-manager task list | grep --count 'running') ((taskcount+=$(/usr/bin/zpool status | grep --count 'scrub in progress'))) ((taskcount+=$(/usr/bin/who | wc -l))) # check for scheduled shutdown /usr/sbin/shutdown --show >/dev/null 2>&1 noschedule=$? if [[ $taskcount -eq 0 && $noschedule -eq 1 ]]; then echo -e "${0##*/} @ Proxmox Backup Server '$(hostname)'\n" echo "The server is idle ($taskcount tasks)." /usr/sbin/shutdown --no-wall -h -P +30 elif [[ $taskcount -gt 0 && $noschedule -eq 0 ]]; then echo -e "${0##*/} @ Proxmox Backup Server '$(hostname)'\n" echo "A shutdown was scheduled, but the server is no longer idle ($taskcount tasks)." /usr/sbin/shutdown --no-wall -c && echo "Shutdown canceled." fi |
Usage
Simply call the script regularly via crontab, systemd timer, …
|
1 |
*/5 * * * * /opt/idle-shutdown.sh |
The server will be shut down with a delay of 30 minutes. If there are new tasks started within this period, the pending shutdown will be canceled. Note: Because of the crontab polling frequency, it is possible to miss a task started in the last five minutes before the shutdown.
Tested with Proxmox Backup Server 9.0
