繁体   English   中英

流浪汉,使用环境变量在ssh中启动命令

[英]Vagrant, launching command in ssh with environment variables

我有一个带有LAMP堆栈和YiiFramework的vagrantbox。 我需要运行一些依赖于环境变量的命令,这些命令是我在.bashrc中设置框的设置(尽管.profile具有相同的行为)。 问题是我想使用ssh启动它们,但是我尝试的所有方法都无法正常工作。 例如:

vagrant ssh -- -t '[path]/./yiic command action'

告诉我我没有设置环境变量。 甚至:

vagrant ssh -- -t 'printenv MYSQL_HOST'

具有以下输出:

rmessineo:~ rmessineo$ switebox ssh -- -t 'printenv MYSQL_HOST'
Connection to 127.0.0.1 closed.
rmessineo:~ rmessineo$ 

但是,当然,如果我登录并相同:

rmessineo:~ rmessineo$ vagrant ssh

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Feb 24 11:02:05 2016 from 10.0.2.2

vagrant@debian-jessie:~$ printenv MYSQL_HOST
127.0.0.1
vagrant@debian-jessie:~$ 

有任何想法吗?

假设vagrant实例的端口为2222 ,则可以运行以下命令:

ssh -p 2222 vagrant@127.0.0.1 'printenv MYSQL_HOST'

密码vagrant ,那么您应该得到结果。

根据实际的流浪者实例更新端口。

我在VM的.profile文件中添加了以下内容

export MY_VAR="hello fred"

然后我可以通过运行来获取新变量的值

fhenri@machine:~/project/examples/vagrant/ubuntu$ vagrant ssh -- -t 'source ~/.profile && printenv MY_VAR'
hello fred
Connection to 192.168.6.120 closed.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM