Idle Proxmox Auto-Shutdown
1. Create the Script
Open the shell of your Proxmox server (via SSH or web UI) and create the script file:
nano /root/shutdown.sh
Paste the following content into the file:
#!/bin/bash
# Check all VMs for running status
VM_RUNNING=$(qm list | grep -c 'running')
# Check all containers for running status
CT_RUNNING=$(pct list | awk '$3 == "running" {print $1}' | wc -l)
# If neither VMs nor containers are running, power off
if [[ "$VM_RUNNING" -eq 0 && "$CT_RUNNING" -eq 0 ]]; then
poweroff
fi
Save and exit (in nano, press CTRL+O
then Enter
, then CTRL+X
).
Make the script executable:
chmod +x /root/shutdown.sh
2. Add Cron Job
Edit the root user's crontab:
crontab -e
Add the following line at the end of the file to execute the script every 3 hours:
0 */3 * * * /root/shutdown.sh
Save and exit the editor.
3. Verify & Test
Your script will now be checked every 3 hours.
If there are no running VMs or containers, the server will power off safely.
You do not need to restart the cron service after editing as Proxmox picks up changes automatically.
Ensure the script path and permissions are correct.
PreviousRemotely Unlocking LUKS-Encrypted Proxmox with Dropbear SSH at BootNextSecure Remote Access with TailScale + Hardened SSH
Last updated