How do I access the Linode-provided environment variables in a StackScript?
Linode
Linode Staff
How do I access the Linode-provided environment variables in a StackScript?
1 Reply
tommydavidson
Linode Staff
When running a StackScript, there are four environment variables provided by default, that are only available while the StackScript is executing. Those variables are:
LINODE_ID
LINODE_LISHUSERNAME
LINODE_RAM
LINODE_DATACENTERID
To access their values, they can be referenced like any other variable, using a command like echo
or printf
. For example:
echo "$LINODE_ID"
printf "%s\n" "$LINODE_LISHUSERNAME"
To save this information to a file, you can use a string of commands like the following:
echo $LINODE_ID >> /root/vars.txt
echo $LINODE_LISHUSERNAME >> /root/vars.txt
echo $LINODE_RAM >> /root/vars.txt
echo $LINODE_DATACENTERID >> /root/vars.txt
After executing those commands inside of your StackScript, you will find their values stored in /root/vars.txt. You can alter the location of the file to any place you'd like to store the data.