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

时间:2021-11-21 19:16:35

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

但它没有工作它给我一个错误

2 个解决方案

#1


1  

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.

另一个问题可能是你的机器上的用户管理员在PATH中没有arp(他是root吗?arp通常在/ sbin /和/ sbin /中通常不在普通用户的PATH中)。

#2


0  

put in subshell. something like this will make things more clear:

放入子壳。这样的事情会让事情变得更加清晰:

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

#1


1  

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.

另一个问题可能是你的机器上的用户管理员在PATH中没有arp(他是root吗?arp通常在/ sbin /和/ sbin /中通常不在普通用户的PATH中)。

#2


0  

put in subshell. something like this will make things more clear:

放入子壳。这样的事情会让事情变得更加清晰:

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