10

First off I feel crazy asking this, sorry if this is a really stupid question. It must be obvious as I have searched everywhere and cannot find an answer!

How I am supposed to run this Azure script to create an Azure Function App? https://learn.microsoft.com/en-us/azure/azure-functions/scripts/functions-cli-create-serverless

#!/bin/bash

# Function app and storage account names must be unique.
storageName=mystorageaccount$RANDOM
functionAppName=myserverlessfunc$RANDOM

# Create a resource group.
az group create --name myResourceGroup --location westeurope

# Create an Azure storage account in the resource group.
az storage account create \
  --name $storageName \
  --location westeurope \
  --resource-group myResourceGroup \
  --sku Standard_LRS

# Create a serverless function app in the resource group.
az functionapp create \
  --name $functionAppName \
  --storage-account $storageName \
  --consumption-plan-location westeurope \
  --resource-group myResourceGroup

Clean up deployment

The page gives an example of how to run it using the console in the portal and the page also suggests I can run it locally if install the Azure CLI which I have. I need to run it from my local machine so that it can be automated with parameters.

However this page tells me nothing.

What should the extension of this file be ? .sh? What command do I use to call the script from my cli?

I have tried just typing the file name saved as .sh

e.g I have az --help and I can't see anything there either.

Lenny D
  • 1,734
  • 4
  • 22
  • 43
  • Do you just want to execute the shell script or set the script as a parameter for other Azure CLI command? – Charles Xu Aug 08 '18 at 01:26
  • I imagine I would want to invoke the Cli and pass a script path along with parameters as this would potentially be part of a CI process. Is this possible ? – Lenny D Aug 08 '18 at 13:54
  • 1
    You can use command [`az vm run-command invoke`](https://learn.microsoft.com/en-us/azure/virtual-machines/linux/run-command). Maybe it's what you want. – Charles Xu Aug 09 '18 at 07:29
  • Yes this seems to be what I need. Thanks! – Lenny D Aug 09 '18 at 12:23
  • Hey @Lenny D. How did you run the script with this command. Can you explain with an example. – Jagrati Modi Apr 01 '19 at 12:24

1 Answers1

7

I just tested this on my Mac.

Copy the script into a file with the .sh extension. I used test.sh.

Make sure you are logged into your local instance of Azure CLI.

Then just run: . /<path>/test.sh

Travis Prescott
  • 407
  • 2
  • 8
  • 1
    There will be a permission problem with the shell script. If you want to execute it you should grant `x` permission to it. This should pay attention to. Or use command `/bin/sh //test.sh`. – Charles Xu Aug 08 '18 at 08:02