0

I have a list of IP addresses, and my end goal is to ssh into each one, and reset them one-at-a-time. I was asked to use Linux / Bash, which I am not extremely familiar. My code right now will take the first IP from the list, and connect to it, but it never moves on past that point. I believe the issue is somewhere between the while read oneip3 and do code. Any help is greatly appreciated.

The way I run this script is as follows: (I have a list of IP addresses in a separate text file):

./runscript.txt ip_list.txt


while read oneip3
do
(sleep 5
echo "yes\r"
sleep 3
echo -e "password\r"
sleep 3
echo -e "reset\r"
sleep 3
echo -e "yes\r"
sleep 20
echo -e "\r"
) | ssh -t -t -oHostKeyAlgorithms=+ssh-dss admin@$oneip3
done < $1
ValleyDigital
  • 1,460
  • 4
  • 21
  • 37
  • 1
    You seem to be missing the `-e` option for the first `echo`. Beyond that, it's hard to say what the problem might be, because we don't know what program is run upon connecting to the remote host. (It doesn't appear to be a shell, given the text you are piping to it.) – chepner Jul 20 '16 at 22:03
  • I reopened this question because `ssh` is here reading from a subshell group and not from the stdin shared by `read` as in the other question. – that other guy Jul 20 '16 at 22:17
  • 1
    @ValleyDigital Is it hanging on the host key verification or password prompts? You can't pipe in answers like that on stdin. Use `-o StrictHostKeyChecking=no` to disable host key checking, and set up a key pair for authentication, then try again. – that other guy Jul 20 '16 at 22:21
  • @thatotherguy - I believe what you are saying is correct. I am getting hung up on the host key verification. I'll try what you suggested. Thank you. – ValleyDigital Jul 20 '16 at 22:35

1 Answers1

0

You didn't provide SSH argument. So it opens an interactive shell. It is a good reason to be stuck on the first machine (maybe there is other reason...)

Try this to debug

... | ssh -t -t -oHostKeyAlgorithms=+ssh-dss "admin@$oneip3" pwd

Other remarks in comment about StrictHostKeyChecking seams good too (if you are really concern by security, you can deploy all needed keys by hand firstly)

mcoolive
  • 3,805
  • 1
  • 27
  • 32