【发布时间】:2020-04-22 22:07:09
【问题描述】:
我已使用 aws CLI 执行的查询以表格格式对文件中的输出进行排序(降序)。我需要从输出文件中获取一个字段并将所有唯一行作为用户选择的选项。这是一个输出文件的例子:
Description Snapshot StartTime
Volume0 snap-x123456789 2020-04-22T20:55:10
Volume10 snap-y123456789 2020-04-22T20:45:09
Volume12 snap-a123456789 2020-04-22T20:40:08
Volume15 snap-b123456789 2020-04-22T20:35:07
Volume0 snap-c123456789 2020-04-22T20:30:06
Volume10 snap-d123456789 2020-04-22T20:25:05
目标是在阅读上述输出后显示所有卷,并提示用户输入卷号,或者用户可以为 ALL 输入 A,以便系统可以恢复该卷的快照。像这样的:
0 - Volume0
10 - Volume10
12 - Volume12
15 - Volume15
这就是我所拥有的,如何让用户输入与卷号对应的数字或输入ALL以恢复所有?我应该使用输出文件中的数组吗?我怎样才能有效地做到这一点?
output() {
echo "Here is a list of volumes found in $region"
for DR in (grep Volume# "$input" | top -n 1)
do
echo $DR
done
echo "Hello, please tell me what Volume you are searching for..(Volume?):"
read volSearch
echo -e "Searching for newest SnapshotIds in region using output file GetfileSnapId for:\n" $volSearch
echo
sleep 5
input="/Users/user/Downloads/GetfileSnapId"
if x=$(grep -m 1 "$volSearch" "$input")
then
echo
echo "$x"
else
echo
echo "$volSearch not found..ending search"
fi
extractSnap=$(echo "$x" | cut -d'|' -f2 )
echo
echo $extractSnap
regionoutput=$(echo "$extractSnap" | awk '{print $4}' )
echo
echo "$regionoutput"
}
【问题讨论】:
标签: bash amazon-web-services command-line-interface