Part 1) I try to execute an echo hostname
on my remote host (using ssh).
just the hostname
command it works. But I have to echo the hostname because I have to copy it.
Part2) Paste the copied hostname (of the host) to a folder which is local. Can someone help me? I tried:
ssh -tt -i key.pem centos@ec2xxx .amazonaws.com sudo sh -c \ "echo `hostname`" >> /myfile
But this is just giving me an empty line. I have to use echo in it (assignement)
This should work:
You're jumping through unnecessary hoops. You can simply run
hostname
as the remote command, and redirect ssh's stdout:For example:
(that's a 5-char hostname in there, redacted!)