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,669

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,427
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