running terminal with script

suppose we have a file
ab
81

and another file
exec < $1
while read line
do
ssh root@172.16.1.$line
done

while running the command
sh file.sh ab

output display as shown
Pseudo-terminal will not be allocated because stdin is not a terminal.
root@172.16.1.81's password:
after writinfg password but it will not run.........

Why is is so that.......????

Your

exec <$1

redirects all script input from whatever $1 is. Thus, any programs started by this script will also be redirected to whatever $1 is. Your starting ssh in interactive mode, which shouldn't take input from a non-terminal.

You don't need this exec line:

cat $1 |
while read line 
do
ssh ....
done

Or maybe you want to use ssh to execute a command and not run interactively. Is that the case?

Still after running the command this dispalys
Pseudo-terminal will not be allocated because stdin is not a terminal.

Yes that is the case want to execute a command and not running interactively.

Right. So run ssh with the command:

ssh user@foreign.host  command