Remote Shell in Linux

245 Views Asked by At

I want to do rsh for 10 servers, i have saved login and server name in one file and trying to run that file using below code. But its showing the output of first line not for other lines.

while read line
do
    rsh -l $line 'hostname;id'
done <TestFIle
1

There are 1 best solutions below

0
Mark Plotnick On

rsh continuously reads its standard input and sends it to the remote, so the first invocation of rsh will read the second through last lines of your file and send them to the first server. (It will do this even if the commands on the server don't actually read their standard input.) With nothing left to read, the read loop will then end.

Try this instead. The -n option to rsh tells it not to read from stdin.

while read line
do
    rsh -n -l $line 'hostname;id'
done <TestFIle