[OT] run command via ssh - problem

Joachim Backes joachim.backes at rhrk.uni-kl.de
Wed Nov 4 13:14:48 UTC 2009


On 11/04/2009 02:10 PM, 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..
>
> Thanks
> Dan
>

Use the following
for i in server1 server2;do ssh root@$i '`hostname`';done.


Explanation: `hostname`, or $(hostname), is already evaluated on the 
source host by your shell (even inside of "...") , not on the target host.
-- 

Joachim Backes <joachim.backes at rhrk.uni-kl.de>

http://www.rhrk.uni-kl.de/~backes


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 6101 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://listman.redhat.com/archives/fedora-list/attachments/20091104/f2131056/attachment-0001.p7s>


More information about the fedora-list mailing list