NET SSH和远程环境 [英] net-ssh and remote environment

查看:57
本文介绍了NET SSH和远程环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用net-ssh库在服务器上执行一些远程命令.

I want to execute some remote command on my server using net-ssh library.

我有以下示例:

Net::SSH::start(host, user, options = {:keys => '~/.ssh/id_rsa'}) do |ssh|
  puts ssh.exec!("echo $PATH")
  ssh.loop
end

结果是:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

The result is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

我的问题是我没有按原样加载PATH.

My problem is that I have not my PATH loaded as it should be.

我还应该有一些RVM路径,并在.zshrc中定义自定义路径.

I should also have some RVM paths, and custom paths defining into my .zshrc.

如何更改此行为以使net-ssh使用我的.zshrc加载默认环境?

How could I change this behavior to let net-ssh to use my .zshrc to load my default environment ?

解决方案:

puts ssh.exec!("source ~/.zshrc; echo $PATH")

推荐答案

您尝试过以下方法吗:

ssh.exec!("source /home/you/.zshrc")
puts ssh.exec!("echo $PATH")

?

这篇关于NET SSH和远程环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆