SSH to remote hosts in shell scripting

Hi There,

I have a file contaning some 100 servers names one by one the file called redhat_servers.txt

I want to prepare a script where it should give me the host name and kernal version.

I wrote like this,

#!/bin/bash
while read line
do
        ssh $line "uname -nr"
done < redhat_servers.txt

but here the problem is, it is ssh to the first line, i mean first server in the redhat_servers.txt file and then script is not moving forward.

I am in /bin/tcsh shell.

Kindly suggest me in the above.

Hi, try using ssh -n

This how I run a check like the one you want.

for s in `cat redhat_servers.txt`
do ssh -q $s uname -rn
done

I hope this helps

The problem is, ssh tries to read from standard input to get more commands.

What is standard input, inside that loop? "redhat_servers.txt". So the ssh command 'eats' all the lines.

ssh -n, or ssh < /dev/null, fixes this as others have noted.

Good luck :slight_smile: