我有一个数组,其中包含一些采用以下格式的亚马逊 ec2 卷快照的 UTC 创建时间:2013-08-09T14:20:47.000Z
我试图找出一种方法来比较数组的元素以确定哪个是最旧的快照并在 Bash 4 中将其删除
我现在拥有的当前代码:
#creates a count of all the snapshot volume-id's and deletes oldest snapshot if
#there are more than 5 snapshots of that volume
declare -A vol_id_count=( ["id_count"]="${snapshot_vols[@]}" )
check_num=5
for e in ${vol_id_count[@]}
do
if (( ++vol_id_count[$e] > $check_num ))
then
echo "first nested if works"
#compare UTC times to find oldest snapshot
#snapshot_time=${snapshot_times[0]}
#for f in ${snapshot_times[@]}
#do
# time= date --date="$snapshot_time" +%s
# snapshot_check=${snapshot_times[$f]}
# echo "check: "$snapshot_check
# check= date --date="$snapshot_check" +%s
# if [[ "$snapshot_time" -gt "$snapshot_check" ]]
# then
# snapshot_time=$snapsnapshot_check
# echo "time: "$snapshot_time
# fi
#done
#snapshot_index=${snapshot_times[$snapshot_time]}
#aws ec2 delete-snapshot --snapshot-id "${snapshot_ids[$snapshot_index]}"
fi
done
我有第一个 for 循环和 if 语句,用于检查某个卷的快照是否超过 5 个,但我正在挠头,试图弄清楚如何比较 UTC 字符串。第二个关联数组会做我想知道的伎俩吗?