- I would like to run a script under a userid on a remote server but the user's environment variables are not set properly.
- Looks like it is not running the user's ".bash_profile".
- Is there any way I can set the user's environment variables before running the script?
Check the user's environment variables:
$ whoami user1 $ env|grep NUM NUM=1999 $ echo $NUM 1999 $ cat ~/.bash_profile | grep NUM export NUM=1999
$ cat /home/user1/test.sh #!/bin/bash echo $NUM >> /home/user1/result.txt 2>&1
Run the script from the remote host via SSH:
# ssh -l user1 10.10.10.10 /home/user1/test.sh firstname.lastname@example.org's password:
Check the result:
$ cat /home/user1/result.txt $
--> The result shows the user's environment variable $NUM is not read.
How can I have it read the user's environment variable described in .bash_profile?
- Red Hat Enterprise Linux 6
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.