如果我使用以下循环运行脚本,则该循环的第一次迭代后它将停止处理。
但是,如果我删除ssh命令,它将遍历整个文件。
#ssh -q ${host} ./fgrepOne.sh "${searchTerm}" '\*.log\*' >> ${outputFile}
while IFS=: read -r host; do
if [[ "$host" == *#* ]] ;
then
echo Skipping $host
continue
fi
echo ssh "${host} ./fgrepOne.sh "'"'${searchTerm}'"'
ssh -q ${host} ./fgrepOne.sh "${searchTerm}" '\*.log\*' >> ${outputFile}
done < $serverList
输出:
ssh servera ./fgrepOne.sh "ERROR"
for host in $(cat ${serverList}); do
if [[ "$host" == *#* ]] ;
then
echo Skipping $host
continue
fi
echo ssh "${host} ./fgrepOne.sh "'"'${searchTerm}'"'
ssh -q ${host} ./fgrepOne.sh "${searchTerm}" '\*.log\*' >> ${outputFile}
done
输出:
ssh servera ./fgrepOne.sh "ERROR"
ssh serverb ./fgrepOne.sh "ERROR"
ssh serverc ./fgrepOne.sh "ERROR"
Skipping #COMMENT
Skipping #server5
Skipping #server6
Skipping #Long
ssh Comment ./fgrepOne.sh "ERROR" <<< Note that this was intended to be part of the previous command.
ssh ./fgrepOne.sh "ERROR"