I am unable to find az commands that allow me to enable the Scheduled auto-shutdown of a VM. I can do this easily through resource manager when deploying a new vm or editing an existing one, but how can I do through bash commands on the Azure Cloud Shell?
Based on my knowledge, currently, Azure CLI 2.0 does not support enable the Scheduled auto-shutdown of a VM.
In Azure Cloud Shell, you could use
crontab to shutdown a VM at specific time. Please refer to the following steps:
export VISUAL=vi in Cloud Shell, then you could edit crontab task with
2.Write a script
az vm deallocate -g <name> -n <>
3.Give executable permissions.
chmod +x ~/.autoshutdown/autoshutdown.sh
4.Edit crontab task,
crontab -e, if you want to shutdown your VM at 22:00, add the following line to the file.
0 22 * * * ~/.autoshutdown/autoshutdown.sh
5.Check crontab task,
You could check the similar blog.