I'm using aws cfn to start ubuntu instances, and I need to pass variables provided in cfn launch script to the scripts on the instance. For example, I may pass db-server=db-2.domain.com and there is a number of scripts on the instance, that want to know this address.At the moment I create a file in /etc/profile.d setting vars with export, but this only works if bash is started as a login shell, which requires extra actions on my part to have these variables everywhere.So I though that maybe I could instead create files in /usr/local/bin, e.g. get-db-host.sh with echo db-2.domain.com as content, this way they would be available to each script with no changes required. Is it a good approach?
Is it a good idea to put environment variables to /usr/local/bin
linux;bash;ubuntu;environment variables
Is it a good approach?I'm pretty sure all the scripts you are talking about are shell scripts.  In this case, you could just put all your variables in a configuration file:db-server=db-2.domain.comPlace that in a standard location (e.g., /usr/local/etc/myapp/) and source it in the other scripts:. /usr/local/etc/myappYou can also use just plain /etc, obviously.