0

The following shell script works only for first server and does not loop to the next. I tried 0< before the ssh command but it still does not return to the shell script once connected.

#!/bin/sh
while read IP
do
ssh root@10.0.0.10 " ssh root@$IP 'ls -lht /log/cdr-csv/ ' " > /tmp/$IP.txt
done << here_doc
18.17.6.19
18.17.10.24
here_doc

How do I run the same command on the second server 18.17.10.24 ?

shantanuo
  • 3,579
  • 8
  • 49
  • 66
  • 2
    It seems likely that your SSH connection to the first server is not existing for some reason. Add a `set -x` to the top of your script. Where does it stop? – Zoredache Oct 09 '14 at 17:04
  • and for more fun debugging output, `ssh -v` – glenn jackman Oct 09 '14 at 23:40
  • 0< /dev/null ssh root@10.0.0.10 This is the correct answer to this question. Someone from server fault has answered before. I posted this as answer and it was deleted by Moderator who claims to be "system administrator since time out of mind". – shantanuo Oct 12 '14 at 10:31
  • @shantanuo: You just posted a line of code without context and it was unclear what you meant. You have used [SF] more than long enough and should know that this is not a proper way to answer, even for your own question. If you would post a proper answer with an explanation, it wouldn't get deleted. – Sven Oct 13 '14 at 14:25

2 Answers2

0

You should send to the remote server the script to be executed. The way your script is written will not work because the here_doc is evaluated locally, not remotely.

Take a look on this answer I provided to another user on this subject.

ThoriumBR
  • 5,302
  • 2
  • 24
  • 34
0

ssh reads stdin unless you provide the -n option. So, the first IP address is consumed by read IP and all the rest of the here-doc is consumed by ssh root@10.0.0.10. Change that to ssh -n root@10.0.0.10

glenn jackman
  • 4,630
  • 1
  • 17
  • 20