while 循环仅在文件的第一行运行

while 循环仅在文件的第一行运行

由于某种原因,我的while循环只运行一次。我看过其他帖子,但似乎无法弄清楚。应该是一个简单的脚本,但它只会运行一次。屏幕输出位于+xbash 脚本中。

LICENSE="1010110.license"
PASS="somepassword"
SSHPASS="/usr/bin/sshpass"
SERVERFILE="/home/user/server.txt"

while read SERVER
do
    if sshpass -p $PASS ssh root@$SERVER '[ -d /etc/something/licenses/ ]'
         then
            echo "The directory is present"
            sshpass -p "$PASS" scp $LICENSE "root@$SERVER":/etc/something/licenses/
         else
            echo "$SERVER does not contain the correct folder, trying 2nd option" >> failures.txt
            if sshpass -p $PASS ssh root@$SERVER '[ -d /etc/something/else/licenses/ ]' 
                then
                    sshpass -p "$PASS" scp $LICENSE "root@$SERVER":/etc/something/else/licenses/
                else
                    echo "$SERVER does not contain either directory" >> failures.txt
            fi

    fi

done < "$SERVERFILE"

这是输出+x

+ read SERVER
+ sshpass -p 'somepassword' ssh root@server1 '[ -d /etc/something/licenses/ ]'
+ echo 'server1 does not contain the correct folder, trying 2nd option'
+ sshpass -p 'somepassword' ssh root@server1 '[ -d /etc/something/else/licenses/ ]'
+ sshpass -p 'somepassword' scp 1010110.license root@server1:/etc/something/else/licenses/
+ read SERVER

看起来它试图SERVER再次阅读,但实际上并没有阅读它。该server.txt文件只是服务器名称的列表。

相关内容