【问题标题】:Ruby Net/SSH - reload bash_profileRuby Net/SSH - 重新加载 bash_profile
【发布时间】:2014-02-19 05:16:30
【问题描述】:

我正在使用 Ruby MRI 1.8.7,并且我有一个连接到服务器并编辑 .bash_profile 文件的 Net-SSH 脚本。 基本上添加了一些别名快捷方式。 .bash_profile 内容示例:

alias test="echo 'test'"

现在,在通过源 .bash_profile 重新加载之前,我无法使用这些别名。 问题是我似乎无法通过 Net-SSH 获取 .bash_profile。 这是我迄今为止尝试过的:

ssh.exec!("source .bash_profile")
ssh.exec!("source /root/.bash_profile")
ssh.exec!("bash -c 'source ~/.bash_profile'")

现在,实际上我什至不需要 Net-SSH 中的别名,但我至少不想在服务器上手动获取 bash_profile。 这是什么问题,有什么解决办法吗?

【问题讨论】:

  • 您是否尝试执行与source 内联的命令以查看会发生什么? (例如source ~/.bash_profile && test
  • 是的,它工作正常。您是否暗示 Ruby/SSH 会话不应该有任何不同?
  • 我的意思是你尝试过通过 Ruby/SSH 执行该命令。也许采购不会在ssh.exec! 语句之间持续存在。
  • 啊,我明白了。但它不起作用:“bash: test1: command not found\n”(来自 .bash_profile: alias test1="echo 'test'")
  • 这个问题解决了吗?我有这个确切的问题。

标签: ruby bash net-ssh


【解决方案1】:

在 bash 中,双引号字符串中不能有 bang (!)。尝试这个: alias test='echo ''test!'''

【讨论】:

  • 感谢我编辑了我的帖子。然而,这只是一个说明性示例,因此实际内容无关紧要。在我的现实生活示例中,别名/快捷方式在手动采购 bash_profile 时工作正常(源 ~/.bash_profile && 测试),但在通过 Ruby/SSH 采购时却不行
【解决方案2】:

看跌

source $HOME/.bash_profile

在 .bashrc 的第一行

【讨论】:

    猜你喜欢
    • 2011-06-04
    • 1970-01-01
    • 1970-01-01
    • 2014-04-24
    • 2011-06-30
    • 2015-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多