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 [email protected] " 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 ?

4
  • 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? Commented Oct 9, 2014 at 17:04
  • and for more fun debugging output, ssh -v Commented Oct 9, 2014 at 23:40
  • 0< /dev/null ssh [email protected] 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". Commented Oct 12, 2014 at 10:31
  • @shantanuo: You just posted a line of code without context and it was unclear what you meant. You have used Server Fault 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. Commented Oct 13, 2014 at 14:25

2 Answers 2

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.

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 [email protected]. Change that to ssh -n [email protected]

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.