我有一个脚本,可以对主机列表执行各种操作。然而,其中一个循环仅将操作应用于文件中的第一个条目,我不明白为什么。
# this loop shows multiple entries in the file...
while read -r target_host ; do
echo "%% read $target_host"
done <"${PHASE_TWO_FILE}"
# this loop only goes around once then exits....
while read -r target_host ; do
cmd="ssh [email protected] 'applyrrdupg.sh ${target_host}'"
echo "DEBUG: Running $cmd"
$cmd >>"$ERRORS_FILE"
RC=$?
if [ 0 -eq "$RC" ]; then
echo "SUCCESS: convert ${target_host}"
echo "$target_host" >>"${PHASE_THREE_FILE}"
echo -e "HOST: $target_host\nSUCCESS\n--" >>"$ERRORS_FILE"
else
echo "ERROR: rrd conversion failed for $target_host"
REVIEW_ERRORS=1
echo -e "HOST: $target_host\nERROR: Conversion failed\nDETAILS: see above\n--" >>"$ERRORS_FILE"
fi
done <"${PHASE_TWO_FILE}"
echo "%% loop exited"
# and just to make sure - lets check again....
while read -r target_host ; do
echo "%% read $target_host"
done <"${PHASE_TWO_FILE}"
这会产生输出:
%% read centos5.southwold.net
%% read centos7.southwold.net
%% read cmk-satellite.southwold.net
DEBUG: Running ssh [email protected] 'applyrrdupg.sh centos5.southwold.net'
SUCCESS: convert centos5.southwold.net
%% loop exited
%% read centos5.southwold.net
%% read centos7.southwold.net
%% read cmk-satellite.southwold.net
我缺少什么?