简体   繁体   English

一些命令无法通过ssh(shell)在远程服务器上运行

[英]some commands not wroking on remote servers through ssh (shell)

I have to run some userdefined commands on remote servers. 我必须在远程服务器上运行一些用户定义的命令。 So I do the following. 因此,我执行以下操作。 It works for many commands such as crontab -l , ls , date +%s , etc... However, it doesn't work for ip addr 它适用于许多命令,例如crontab -llsdate +%s等等。但是,它不适用于ip addr

When I actually ssh INSIDE those server ip addr works fine. 当我实际上在ssh INSIDE中运行时,那些服务器ip addr正常工作。 But when I execute it using ssh it doesnt. 但是,当我使用ssh执行它时,它不会。

This is how I execute it. 这就是我执行它的方式。

$ sshpass -p myPassword ssh -q root@127.0.0.1 'ip addr' > $PWD/tmp
$ cat $PWD/tmp

Again, this works for any commands I've tried so far except ip addr . 再说一次,这适用于到目前为止我尝试过的所有命令,除了ip addr For ip addr it gives the following output 对于ip addr它提供以下输出

bash: ip: command not found

So i was wondering why and if there's anything wrong I'm doing.... 所以我想知道为什么,如果有什么问题我在做...。

Also, please don't sugges to use rsync or any other nondefault linux command since the environment I work in does not have them nor do I have the permission to install. 另外,请不要使用rsync或任何其他非默认linux命令,因为我工作的环境没有它们,也没有安装许可。

Thank you in advance 先感谢您

This is caused because a non-interactive ssh session does not source your login profile, which amongst other things is setting your PATH variable. 这是由于非交互式ssh会话无法获取您的登录配置文件而导致的,该配置文件尤其是设置PATH变量。

The default path does not contain /sbin , which is the usual location of the ip command. 缺省路径不包含/sbin ,这是ip命令的常规位置。

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

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