【发布时间】:2013-12-30 10:50:29
【问题描述】:
我在 shell 脚本中有如下代码:
# Setup the command.
command=`ec2-describe-snapshots | grep pending | wc -l`
# Check if we have any pending snapshots at all.
if [ $command == "0" ]
then
echo "No snapshots are pending."
ec2-describe-snapshots
else
# Wait for the snapshot to finish.
while [ $command != "0" ]
do
# Communicate that we're waiting.
echo "There are $command snapshots waiting for completion."
sleep 5
# Re run the command.
command=`ec2-describe-snapshots | grep pending | wc -l`
done
# Snapshot has finished.
echo -e "\n"
echo "Snapshots are finished."
fi
此代码有时可以正常工作,有时却不能正常工作。它进入一个无限循环。我想做这样的事情我想检查ec2-describe-snapshot 的输出,如果 snaphost 处于挂起状态。如果是,它应该等到所有快照都完成。
ec2-describe-snapshots 的输出是
SNAPSHOT snap-104ef62e vol-a8 completed 2013-12-12T05:38:28+0000 100% 109030037527 20 2013-12-12: Daily Backup for i-3ed09 (VolID:vol-aecbbcf8 InstID:i-3e2bfd09)
SNAPSHOT snap-1c4ef622 vol-f0 pending 2013-12-12T05:38:27+0000 100% 109030037527 10 2013-12-12: Daily Backup for i-260 (VolID:vol-f66a0 InstID:i-2601)
【问题讨论】:
-
提示,也许在你的脚本中使用
logger。 -
那是什么?我什么都没得到
-
您的
echo命令是否显示有非零数量的快照等待完成?或者你看到There are 0 snapshots waiting for completion并且它还在循环? -
no 不显示非零。喜欢
There are 1 snapshots waiting for completion. -
这确实意味着至少有一个待处理的快照...
标签: linux shell amazon-ec2