You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Preview: Run scripts in your Linux VM by using managed Run Commands
14
+
# Run scripts in your Linux VM by using managed Run Commands
15
15
16
16
**Applies to:**:heavy_check_mark: Linux VMs :heavy_check_mark: Flexible scale sets
17
17
18
-
> [!IMPORTANT]
19
-
> **Managed Run Command** is currently in public preview.
20
-
> This preview version is provided without a service-level agreement, and we don't recommend it for production workloads. Certain features might not be supported or might have constrained capabilities.
21
-
> For more information, see [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
22
18
23
19
The Run Command feature uses the virtual machine (VM) agent to run scripts within an Azure Linux VM. You can use these scripts for general machine or application management. They can help you quickly diagnose and remediate VM access and network issues and get the VM back to a good state.
24
20
25
21
The *updated* managed Run Command uses the same VM agent channel to execute scripts and provides the following enhancements over the [original action oriented Run Command](run-command.md):
26
22
- Support for updated Run Command through ARM deployment template
27
23
- Parallel execution of multiple scripts
28
-
- Sequential execution of scripts
29
-
- RunCommand script can be canceled
24
+
- Sequential execution of scripts
30
25
- User specified script timeout
31
26
- Support for long running (hours/days) scripts
32
27
- Passing secrets (parameters, passwords) in a secure manner
33
28
34
29
35
-
## Register for preview
36
-
37
-
You must register your subscription in order to use managed Run Command during public preview. Go to [set up preview features in Azure subscription](../../azure-resource-manager/management/preview-features.md) for registration instructions and use the feature name `RunCommandPreview`.
38
-
39
30
## Azure CLI
40
31
41
32
The following examples use [az vm run-command](/cli/azure/vm/run-command) to run shell script on an Azure Linux VM.
@@ -61,6 +52,10 @@ This command will retrieve current execution progress, including latest output,
61
52
az vm run-command show --name "myRunCommand" --vm-name "myVM" --resource-group "myRG" --expand instanceView
62
53
```
63
54
55
+
> [!Note]
56
+
> Output and error fields in `instanceView` is limited to last 4KB.
57
+
> If you'd like to access the full output and error, you have the option of forwarding the output and error data to storage append blobs using `-outputBlobUri` and `-errorBlobUri` parameters while executing Run Command using `Set-AzVMRunCommand` or `Set-AzVMssRunCommand`.
58
+
64
59
### Delete RunCommand resource from the VM
65
60
Remove the RunCommand resource previously deployed on the VM. If the script execution is still in progress, execution will be terminated.
66
61
@@ -101,6 +96,101 @@ This command will retrieve current execution progress, including latest output,
### Create or update Run Command on a VM using SourceScriptURI (storage blob SAS URL)
100
+
Create or update Run Command on a Windows VM using a SAS URL of a storage blob that contains a PowerShell script. `SourceScriptUri` can be a storage blob’s full SAS URL or public URL.
101
+
102
+
> [!NOTE]
103
+
> The SAS URL must provide read access to the blob. An expiration time of 24 hours is suggested for the SAS URL. SAS URLs can be generated on Azure portal using blob's options, or SAS token using `New-AzStorageBlobSASToken`. If generating SAS token using `New-AzStorageBlobSASToken`, your SAS URL = "base blob URL" + "?" + "SAS token from New-AzStorageBlobSASToken"
### Get a Run Command Instance View for a VM after Creating or Updating Run Command
110
+
111
+
Get a Run Command for VM with Instance View. Instance View contains the execution state of Run Command (Succeeded, Failed, etc.), exit code, standard output and standard error generated by executing the script using Run Command. A non-zero ExitCode indicates an unsuccessful execution.
### Create or update Run Command on a VM using SourceCommandId
143
+
Create or update Run Command on a VM using pre-existing `commandId`. Available commandIds can be retrieved using [Get-AzVMRunCommandDocument](/powershell/module/az.compute/get-azvmruncommanddocument).
### Create or update Run Command on a VM using OutputBlobUri, ErrorBlobUri to stream standard output and standard error messages to output and error Append blobs
150
+
151
+
Create or update Run Command on a VM and stream standard output and standard error messages to output and error Append blobs.
> Output and error blobs must be of type `AppendBlob` and their SAS URLs must provide read, append, create, write access to the blob. An expiration time of 24 hours is suggested for the SAS URL. If output or error blob does not exist, a blob of type AppendBlob will be created. SAS URLs can be generated on Azure portal using blob's options, or SAS token using New-AzStorageBlobSASToken. If generating SAS token using `New-AzStorageBlobSASToken`, SAS URL = base blob URL + "?" + SAS token from `New-AzStorageBlobSASToken`.
159
+
160
+
### Create or update Run Command on a VM, run the Run Command as a different user using RunAsUser and RunAsPassword parameters
161
+
Create or update Run Command on a VM, run the Run Command as a different user using `RunAsUser` and `RunAsPassword` parameters. For RunAs to work properly, contact admin of VM and make sure user is added on the VM, user has access to resources accessed by the Run Command (Directories, Files, Network etc.), and in case of Windows VM, 'Secondary Logon' service is running on the VM.
> Note SAS URL must provide read access to the blob. An expiration time of 24 hours is suggested for SAS URL. SAS URLs can be generated on Azure portal using blob's options, or SAS token using New-AzStorageBlobSASToken. If generating SAS token using New-AzStorageBlobSASToken, SAS URL = base blob URL + "?" + SAS token from `New-AzStorageBlobSASToken`.
175
+
176
+
### Create or update Run Command on a VM instance using Parameter and ProtectedParameter parameters (Public and Protected Parameters to script)
Use `ProtectedParameter` to pass any sensitive inputs to script such as passwords, keys etc.
188
+
189
+
- Windows: Parameters and ProtectedParameters are passed to script as arguments are passed to script and run like this `myscript.ps1 -publicParam1 publicParam1value -publicParam2 publicParam2value -secret1 secret1value -secret2 secret2value`
190
+
- Linux: Named Parameters and its values are set to environment config, which should be accessible within the `.sh` script. For Nameless arguments, pass an empty string to name input. Nameless arguments are passed to script and run like this - `myscript.sh publicParam1value publicParam2value secret1value secret2value`
191
+
192
+
193
+
104
194
### Delete RunCommand resource from the VM
105
195
Remove the RunCommand resource previously deployed on the VM. If the script execution is still in progress, execution will be terminated.
106
196
@@ -175,11 +265,10 @@ GET /subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers
175
265
GET /subscriptions/<subscriptionId>/resourceGroups/<resourceGroupName>/providers/Microsoft.Compute/virtualMachines/<vmName>/runcommands/<runCommandName>?$expand=instanceView&api-version=2019-12-01
176
266
```
177
267
178
-
### Cancel a specific Run Command deployment
179
-
180
-
To cancel a running deployment, you can PUT or PATCH on the running instance of Run Command and specify a blank script in the request body. This will cancel the ongoing execution.
Copy file name to clipboardExpand all lines: articles/virtual-machines/run-command-overview.md
+6-7Lines changed: 6 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,11 @@
2
2
title: Run scripts in a Windows or Linux VM in Azure with Run Command
3
3
description: This topic provides an overview of running scripts within an Azure virtual machine by using the Run Command feature
4
4
ms.service: virtual-machines
5
-
author: cynthn
6
-
ms.author: cynthn
7
-
ms.date: 10/27/2021
5
+
author: nikhilpatel909
6
+
ms.author: erd
7
+
ms.date: 11/03/2022
8
8
ms.topic: how-to
9
-
ms.reviewer: jushiman
9
+
ms.reviewer: erd
10
10
ms.custom: devx-track-azurepowershell
11
11
12
12
---
@@ -19,9 +19,8 @@ Run Command uses the virtual machine (VM) agent to run scripts within an Azure W
19
19
The original set of commands are action orientated. The updated set of commands, currently in Public Preview, are management orientated and enable you to run multiple scripts and has less restrictions. This article will explain the difference between the two sets of run commands and help you decide which set is the right one to use in your scenario.
20
20
21
21
> [!IMPORTANT]
22
-
> **Managed Run Command** is currently in public preview.
23
-
> This preview version is provided without a service-level agreement, and we don't recommend it for production workloads. Certain features might not be supported or might have constrained capabilities.
24
-
> For more information, see [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
22
+
> **Managed Run Command** is currently available in Azure CLI, PowerShell, and API at this time.
0 commit comments