This might be a simple question, but I can't find the answer out there anywhere. I'm trying to write a loop to SSH to a server for me to then copy/paste some commands in. Once I'm done, I type 'exit' and the loop should then automatically SSH to the next server in line.
The 'dbs_group' file contains 5 hostnames, one per line. Nothing else.
Seems to work fine in a FOR loop, but not in a WHILE loop.
For example (server names replaced with 'xxx'):
[chris@x] for HOST in $(cat dbs_group); do ssh $HOST; done
Last login: Thu Apr 23 10:08:51 2015 from xxx.com
[chris@xxx1] exit
logout
Connection to xxx1 closed.
Last login: Sat Apr 18 13:56:28 2015 from xxx.com
[chris@xxx2] exit
logout
Connection to xxx2 closed.
etc., which is what I was expecting.
But using a WHILE loop:
[chris@x] cat dbs_group | while read HOST; do ssh $HOST; done
Pseudo-terminal will not be allocated because stdin is not a terminal.
-bash: line 1: xxx1: command not found
-bash: line 2: xxx2: command not found
-bash: line 3: xxx3: command not found
-bash: line 4: xxx4: command not found
-bash: line 5: xxx5: command not found
[chris@x]
I understand that the error above might be resolved by using 'ssh -t -t' but I'm just trying to figure out why the two different loops respond differently. I thought both of them would process the dbs_group file line per line and assign the variable to HOST.
Thanks,
Chris