Script does not read input file

Hi everyone, I have problems with this script.
This script should check for a folder for each server in the list of the list.txt file.
The script only checks the first host, and then exits, why?

#!/bin/bash
file='/etc/list.txt'
while read line; do
echo $line
if ssh root@$line "stat /var > /dev/null 2>&1"; then
echo "File exists"
else
echo "File does not exist"
fi
done < $file

thank you very much for helping
n

Welcome to the forum.

That's because the ssh eats up all stdin from the redirected file. Try its -n option.

1 Like

Thankuuuuuuuuuuuuuuuu very much !!!
Yessss, now It's working.
I've just only add the -n option to ssh command.

byezzzzzz
nashrik