我想实现这样的功能:我正在创建卷快照(使用亚马逊 ec2 工具),并将最新快照的详细信息存储在文件中。
#Create snapshots of all attached volumes
echo "Create snapshots of all attached volumes"
read -rsp $'Press enter to continue...\n'
awk '{print $2, $3}' "$EC2_HOME/ActiveVolumes_$today_date" | while read vol_id inst_id; do
awk '{print $3, $5}' "$EC2_HOME/Instances_$today_date" | while read inst_id2 name; do
if test "$inst_id" = "$inst_id2"; then
echo ec2-create-snapshot "$vol_id" -d "$today_date: Daily Backup for $inst_id (VolID:$vol_id InstID:$inst_id)"
ec2-create-snapshot "$vol_id" -d "$today_date: Daily Backup for $inst_id (VolID:$vol_id InstID:$inst_id)"
fi
done
done
#Create a file with all latest snapshots
echo "Create a file with all latest snapshots"
read -rsp $'Press enter to continue...\n'
latestdate=$(ec2-describe-snapshots | grep ^SNAPSHOT | sort -rk 5 | awk '{print substr($5, 1, 10); exit}')
ec2-describe-snapshots | grep "^SNAPSHOT.*$latestdate" > "$EC2_HOME/SnapshotsLatest_$today_date"
我想做一件事。我想根据一个条件在两个代码块之间等待。我想在执行第一个代码块后等待。我想检查状态是否已完成然后执行下一个代码块。
SNAPSHOT snap-7749 vol-86d0 pending 2013-12-11T04:17:57+0000 100% 109030037527 35 EBS_Automated_Snapshot_12-10-2013-20:20:13
SNAPSHOT snap-e2f3dc vol-80 completed 2013-12-11T04:16:49+0000 100% 109030037527 35 EBS_Automated_Snapshot_12-10-2013-20:19:05
最佳答案
To check if status of is completed then execute next block of code.
您还可以使用“; && ||”之一这 ;只是将一个命令与另一个命令分开。 && 表示仅在前一个命令成功的情况下才运行以下命令” || - 如果不成功。 Examples
如果还不够,还有 sleep 和等待命令:
- 等待:wait、waitpid、waitid - 等待进程更改状态
- sleep :延迟指定的时间
To put a wait after the first block of code is executed. Just use sleep num.
echo "hello"
# wait 5 seconds
sleep 5
echo "Bye"
更多信息:男人 sleep 。
关于linux - 如何在代码块之间插入等待,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20513439/