Hi ,
I am running a script on multiple servers.When I run that script on one server,I want to exit from that server and want to go to next server.PFB script:
Suppose there are 3 servers:server1,server2,server3.I am currently in server1.
for h in {2..3}
do
ssh username@server$h <<EOF
echo "server$h" >>res1.txt
echo "hi">>res1.txt
exit
EOF
done
Its givine me error"unexpected end of file".Can you please help.
Thanks Agama.It worked but I have another problems:
1.I am ruuning this script on multiple servers but I want the output to be save in same file at one location.
2.I am getting error "Pseudo-terminal will not be allocated because stdin is not a terminal",should I use
ssh -t -t username@server$h <<EOF
The psuedo terminal message is just a warning. It is being issued because you are redirecting the commands in from the here doc. If you use the -t options, you'll see the message of the day -- something you probably don't want. In my opinion you can ignore the message.
If you want output from all scripts in one file on the host that is generating the commands, then do something like this:
for h in host1 host2 host3
do
ssh user@$h <<END
hostname
END
done >/tmp/output
This will write the output of the hostname command from each host in the tmp file.