Share via


how can I set environment variable using Custom linux Extension?

Question

Saturday, November 25, 2017 9:27 AM

I tried to set environment variables using Custom Linux extension but that is not working. Is there any other way to add environment variable on Linux Virtual machine

#!/bin/bash
                
export cid=$1

All replies (4)

Monday, December 25, 2017 4:53 AM âś…Answered | 1 vote

To set an environment variable on a virtual machine for all the users, you need to append the export line to the /etc/profile file.

Here is an example base on https://docs.microsoft.com/en-us/azure/virtual-machines/linux/extensions-customscript:

mgmt $ cat script.sh
#!/bin/bash
echo "export cid=$1" >> /etc/profile

mgmt $ cat protected-config.json
{
  "commandToExecute": "./script.sh whatever"
}

After running the custom script, you can log in to your vm and you should see that the cid variable is set to whatever you set it to.

target $ echo $cid
whatever

Hope this helps


Saturday, November 25, 2017 11:19 AM

Could you help me, if the CSE extension provisioning was successfully completed?

What is the CSE version you are using?

You may also refer the below article:

/en-us/azure/virtual-machines/linux/extensions-customscript#troubleshooting

Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.


Thursday, December 21, 2017 1:43 PM

Linux Custom extension was created successfully but the export command is not working. I was following this link /en-us/azure/virtual-machines/linux/classic/lamp-script?lf-content=191307186:761019221&hubRefSrc=twitter to set an environment variable on a virtual machine.

As much as I know that export command will not work until we run a shell script using source command but when I tried to run a script with source command then it gives me error like Error message: \Malformed status file (000003)Invalid status/status: failed\. 

 


Monday, December 25, 2017 5:38 AM

Thank you @johan_burati It worked.