简体   繁体   中英

Custom Script for Linux - how to execute bash script from particular folder

I am new to Azure.

We have created one small website just as a POC in which I need to select the VM name and Resource group name in which that VM is present. And then I need to mention the command which I need to execute and then click on execute button which will execute the command.

Now what I did, I created one bash script file named as trial.sh in user home directory in Linux. Now I am trying to execute it by giving

./trial.sh

Something like this -

在此处输入图片说明

But when I am checking under Azure portal VM extension it is giving me an error as -

Enable failed: failed to execute command: command terminated with exit status=127 [stdout] [stderr] /bin/sh: ./trial.sh: No such file or directory

So by seeing the error that I guessing that I am creating bash file in wrong location. So just want to know that where should I keep the file under Linux VM so that it will not give me this error and will run successfully.

Note: In pic the in "Command file path" option I need to mention blob storage path where my script is present. But my requirement is that the script should be present in Linux VM itself.

I have also gone through this link but no luck - https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-linux

Can someone please help me with this requirement.

Thanks in advance!

Try absolute path like

/user_home_directory/trial.sh

Note: dot charater in ./ mean your current directory

Try changing working dir in a subshell, and execute the command.
This is the bash syntax

(cd SOME_PATH && exec_some_command)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM