[OT] run command via ssh - problem

Bryn M. Reeves bmr at redhat.com
Wed Nov 4 13:25:18 UTC 2009


On Wed, 2009-11-04 at 13:10 +0000, Dan Track wrote:
> Hi,
> 
> I'm running a command like this:
> 
> for i in server1 server2;do ssh root@$i "`hostname`";done.
> 
> However the hostname command always outputs the hostname of the server
> that the above command is run from. I'd like to know how to run this
> hostname command so that it actually runs on server 1, server2 etc..

Just remove the backticks and quotes around hostname?

for i in server1 server2;do ssh root@$i hostname;done

The backticks tell the shell (on your machine) to run the command inside
the backticks and replace that part of the command line with the output
of the command so you actually end up with a command line like:

for i in server1 server2;do ssh root@$i mylocalhostname;done.

Regards,
Bryn




More information about the users mailing list