How to set environment variable for root user at startup?

I am trying to add memory usage monitoring to the instance monitoring tab on console.aws.amazon.com. This is an instance of Amazon Linux AMI 2013.09.2. I found Amazon CloudWatch Monitoring Scripts for Linux and, in particular, mon-put-instance-data.pl which allow me to collect memory statistics and report it to CloudWatch as user metrics.

To do this, I need to set the AWS_CREDENTIAL_FILE environment variable to point to the file containing my AWSAccessKeyId and AWSSecretKey. I do this by typing:

export AWS_CREDENTIAL_FILE=/home/ec2-user/aws-scripts-mon/awscreds.template

In order not to introduce this again and again, I am looking for a way to set the environment variable at startup. I tried to add code to these files:

/etc/rc.local file
/etc/profile
/home/ec2-user/.bash_profile

How does adding a line of code in any of the files seem to work when I switch to root , where should I put it? If I set the variable to / home / ec 2-user / .bash_profile, the variable will be set for user ec2, but not for root. If I then sudo -E su, it works, but I don't know if this is the best way to do this?

+4
source share
1 answer

Create a sh file and put the code in it. Then put this sh file in the /etc/profile.d/ folder .

Note. create this sh file using the root user.

sh , .

+4

All Articles