user2642601
user2642601

Reputation: 265

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 [email protected] arp\ -an|grep\ lanx >lanx

but it is not working its giving me an error

Upvotes: 0

Views: 671

Answers (2)

Michael Martinez
Michael Martinez

Reputation: 2853

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

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

Upvotes: 0

lukash
lukash

Reputation: 784

ideally just put the commands in quotes like this:

ssh [email protected] '/sbin/arp -an | grep lanx' > lanx

or

ssh [email protected] '/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.

Upvotes: 1

Related Questions