Google
 

Friday, July 18, 2014

Using Azure command line tools in Windows batch files

I have an Azure IaaS environment for development and experiments. The environment consists of 3 machines. I wanted to automate starting and shutting down the VMs in this environment.
I used Azure Command-Line Interface to create two batch files, one to start the environment and the other to stop it.

The scripts looks like:

azure vm start VMName1
azure vm start VMName2
azure vm start VMName3


and

azure vm shutdown VMName3
azure vm shutdown VMName2
azure vm shutdown VMName1


But when I executed the batch files, only the first command is executed then the script just terminates even if the command is successful. I had no clue why!!

I asked my friend @mShady who thankfully pointed me to this stack overflow thread: http://stackoverflow.com/a/4036937. The answer tells: "you must call another script using the call command so it knows to return back to your script after the called script completes. Try prepending call to all commands."

So I added call to the batch files:

call azure vm start VMName1
call azure vm start VMName2
call azure vm start VMName3

and

call azure vm shutdown VMName3
call azure vm shutdown VMName2
call azure vm shutdown VMName1


And it worked.

The documentation for call mentions that it "Calls one batch program from another without stopping the parent batch program".


After checking, I found that the azure command is a batch file that internally calls node. And that was the issue.
The path of the batch file (which is in the path environment variable to be visible anywhere) is: "C:\Program Files\Microsoft SDKs\Windows Azure\CLI\wbin\azure.cmd"

15 comments:

Unknown said...

Awesome - thanks!

Anonymous said...

Hi,
How can Azure copy(AzCopy) command be defined in the batch file?

Hesham A. Amin said...

@Anonymous:
If you have the command in your PATH environment variable then you should be able to call it normally from the batch file. Did you face any specific challenges with it?

Matias said...

The separate applications in a suite usually have a user interface that has some commonality making it easier for the user to learn and use each application. OceanOfGames

ocean games said...

The separate applications in a suite usually have a user interface that has some commonality making it easier for the user to learn and use each application. OceanOfGames

ocean games said...

If you have the command in your PATH environment variable then you should be able to call it normally from the batch file. Did you face any specific challenges with it? GetInto Pc

GOOGLE CROM said...

The separate applications in a suite usually have a user interface that has some commonality making it
filehippo

Nime Patel said...

It was nice articles . Very informative and expressive .things are easily explained by admin,i was downloaded some days before but I got error while installing , I thing somewhere i made mistake. Now , I find my Fault after this very good readable blog . so I am very Thankful to The Admin and Please Buddy Share your Knowledge Time to Time .
filehippo
file hippo
File hippo
Download Free PC Software
File hippo

Phone Advice said...

Free Download Software

kaga koko said...

download game for window pc at ovagames

varsha said...

It might have been decent articles. Verwoerd educational Furthermore expressive. Things would undoubtedly demonstrated by admin,i might have been downloaded a few times When However i got lapse same time introducing , i thing some place i made error. Notwithstanding , i find my shortcoming following this exceptionally great discernable blog.

filehippofree1 said...

awesome blog admin..

Ella lily said...

I needed to thank you for this incredible read!! I unquestionably adored each and every piece of it. I have you bookmarked your site to look at the new stuff you post. Getintopc

getintopc Free Download Software said...

It was nice articles . Very informative and helpful. thanks for sharing it. i will bookmark your site for comes again. www.getinto-pc.co

file hippo said...

Nice Post.Thanks for sharing this information.I read your post very useful and helpful site.Really Thanks.

filehippo