Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run command as Rest API - body of the API call documentation not clear #5

Open
anindya5 opened this issue Sep 26, 2019 · 4 comments
Open

Comments

@anindya5
Copy link

anindya5 commented Sep 26, 2019

I was following this documentation and trying to run a simple shell script in a vm using this.

https://docs.microsoft.com/en-us/rest/api/compute/virtual%20machines%20run%20commands/runcommand#runcommandinputparameter

But what needs to be the content of the body of the post request is not clear. The commandID can be RunShellScript but where doe we provide the script value.

script: 'scriptname'
script: 'sh scriptname'

and other each resulting in

{
"error": {
"code": "BadRequest",
"message": "Error converting value "/home/adminwm/quick-python-test.sh" to type 'System.Collections.Generic.List`1[System.String]'. Path 'script', line 3, position 52.",
"target": "runCommandInput.script"
}
}

@anindya5
Copy link
Author

I can use run command from portal and azure cli, but nt as rest api

@Et3rnal
Copy link

Et3rnal commented Nov 20, 2020

POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/runCommand?api-version=2020-06-01

BODY:
{ "commandId": "RunPowerShellScript", "script": [ "c:\\testps.ps1 paramHere", ], "parameters": [ { "name": "arg1", "value": "not working" } ] }

This is what I was able to do, the parameters don't work if you use $arg1 but you can just pass it after the file location.

Executing the script directly didn't work for me.

@koralski
Copy link
Contributor

To pass arg1 to the script you need to define that parameters on top of the script:
script: [ "param([string]$arg1,[string]$arg2);c:\testps.ps1 $arg1 $arg2" ]

@koralski
Copy link
Contributor

I was following this documentation and trying to run a simple shell script in a vm using this.

https://docs.microsoft.com/en-us/rest/api/compute/virtual%20machines%20run%20commands/runcommand#runcommandinputparameter

But what needs to be the content of the body of the post request is not clear. The commandID can be RunShellScript but where doe we provide the script value.

script: 'scriptname'
script: 'sh scriptname'

and other each resulting in

{ "error": { "code": "BadRequest", "message": "Error converting value "/home/adminwm/quick-python-test.sh" to type 'System.Collections.Generic.List`1[System.String]'. Path 'script', line 3, position 52.", "target": "runCommandInput.script" } }

script is an array of strings to support multiline in json. Try using:
script: ['./scriptname']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants