我有两台服务器X(主机)和Y(远程)。 脚本abc.sh保存在Y服务器上。 我使用ssh命令从服务器X运行abc.sh。
脚本运行成功,但包含服务器Y的环境变量(保存在/.bash_profile中)的命令给出空白输出。
当我从服务器Y本身运行abc.sh时,所有命令都成功运行。
我的问题是如何包含远程服务器(Y)的环境变量,以便完整的脚本将成功执行。
注意:我没有对etc目录的写入权限,所以我无法更改任何内容。
提前致谢!
I have two servers X(host) and Y(remote). A script abc.sh is saved on Y server. I am running abc.sh from server X using ssh command.
Script is running successfully but the commands which contain the environment variables(kept in /.bash_profile) of server Y are giving blank output.
When I am running abc.sh from server Y itself, all commands running successfully.
My question is how to include the environment variables of remote server(Y) so that full script will execute successfully.
NOTE : I don't have write access to etc directory so I can't change anything in it.
Thanks in advance!
最满意答案
您可以包含您的环境变量,如下所示:
ssh user@host_y 'source ~/.bash_profile; /path/to/your/script/abc.sh'由于直接命令运行不是交互式shell,因此您的变量将无法在此运行。 source将在当前shell中运行脚本,并将该文件中的可见环境变量发送到脚本。
You can include your environment variables like following:
ssh user@host_y 'source ~/.bash_profile; /path/to/your/script/abc.sh'Since direct command run is not an interactive shell, your variable will not work there. source will run script in your current shell and make visible environment variables in that file to your script.
更多推荐
发布评论