ホストリストに対してさまざまなタスクを実行するスクリプトがあります。ただし、ループの1つはファイルの最初の項目にのみ操作を適用し、その理由を理解できません。
# 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
私は何を見逃していますか?