1

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?

0

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:

1.export VISUAL=vi in Cloud Shell, then you could edit crontab task with vi.

2.Write a script ~/.autoshutdown/autoshutdown.sh

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, crontab -l

You could check the similar blog.

| improve this answer | |
  • I see you ask a question on SF, the root reason is your script file type is dos(when you create a file on Windows, the file type is dos by default), but on linux it needs unix file type. So, you will get the error log. You could use dos2unix change file type. Please refer to this stackoverflow.com/questions/82726/… – Shui shengbao Sep 27 '17 at 3:04
  • But Cloud shell does not install dos2unix, you need transfer on your local linux or use Notepad ++ change it. – Shui shengbao Sep 27 '17 at 3:05
  • DOS vs. Unix Line Endings please refer to this link:cs.toronto.edu/~krueger/csc209h/tut/line-endings.html – Shui shengbao Sep 27 '17 at 3:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.