简体   繁体   English

Bash脚本在多个服务器上执行命令

[英]Bash script execute command on multiple servers

I'm trying to login into multiple servers and execute the following command: 我正在尝试登录多台服务器并执行以下命令:

arp -an|grep lanx>lanx

I'm using this method: 我正在使用这种方法:

ssh admin@10.x.x.x arp\ -an|grep\ lanx >lanx

but it is not working its giving me an error 但它无法正常工作给我一个错误

ideally just put the commands in quotes like this: 理想情况下,只需将命令放在这样的引号中:

ssh admin@10.x.x.x '/sbin/arp -an | grep lanx' > lanx

or 要么

ssh admin@10.x.x.x '/sbin/arp -an' | grep lanx > lanx

The other problem might be the user admin on your machine does not have arp in PATH (is he root? arp is usually in /sbin/ and /sbin/ is usually not in PATH of a regular user. 另一个问题可能是您计算机上的用户admin在PATH中没有arp(他是root吗?arp通常在/ sbin /中,而/ sbin /通常不在普通用户的PATH中。

put in subshell. 放在subshel​​l中。 something like this will make things more clear: 这样的事情会使事情变得更清楚:

(ssh xxxx arp -an) | grep lanx > /tmp/lanx

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

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