-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgcp-show-my-undeleted-searches.sh
executable file
·99 lines (88 loc) · 3.33 KB
/
gcp-show-my-undeleted-searches.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
# gcp-show-my-undeleted-searches.sh: This script shows my undeleted searches in
# GCP and their status
#
# Author: Christiam Camacho ([email protected])
# Created: Tue 17 Aug 2021 09:57:27 PM EDT
set -o pipefail
shopt -s nullglob
username=`whoami`
verbose=0
command -v elastic-blast >&/dev/null || { echo "elastic-blast must be in your PATH for this script to work"; exit 1; }
usage() {
echo -e "$0 [-h] [-u USERNAME] [-v]\n"
echo -e "This script shows ElasticBLAST searches that have not been deleted on GCP and their status\n"
echo -e "Options:"
echo -e "\t-u USERNAME: Show ElasticBLAST searches for user USERNAME (default: $username)"
echo -e "\t-v: Show verbose output, i.e.: displays your GCP configuration settings"
echo -e "\t-h: Show this message"
}
check_status() {
results=$1
created=$2
status_file=$3
now=$(date -u +"%s")
SECONDS_IN_A_DAY=$((24*60*60))
if egrep -q '^Your ElasticBLAST search succeeded,' $status_file; then
case `uname` in
Linux)
created_date=$(date -d "$created" +"%s")
;;
Darwin)
created_date=$(date -j -f "%F %T" "$created" +"%s")
;;
esac
if [ $(($now - $created_date)) -gt $SECONDS_IN_A_DAY ]; then
echo "Please run 'elastic-blast delete --results $results --gcp-project $ELB_GCP_PROJECT --gcp-region $ELB_GCP_REGION --gcp-zone $ELB_GCP_ZONE'"
fi
fi
}
while getopts "u:vh" OPT; do
case $OPT in
u) username=${OPTARG}
;;
v) verbose=1
;;
h) usage
exit 0
;;
esac
done
if [ -z "${ELB_GCP_PROJECT}" ]; then
export ELB_GCP_PROJECT=`gcloud config get-value core/project`
fi
if [ -z "${ELB_GCP_REGION}" ]; then
export ELB_GCP_REGION=`gcloud config get-value compute/region`
fi
if [ -z "${ELB_GCP_ZONE}" ]; then
export ELB_GCP_ZONE=`gcloud config get-value compute/zone`
fi
if [ $verbose -eq 1 ]; then
echo -n "Account: " ; gcloud config get-value core/account
echo "Project: $ELB_GCP_PROJECT"
echo "Region: $ELB_GCP_REGION"
echo "Zone: $ELB_GCP_ZONE"
fi
TMP=`mktemp -t $(basename -s .sh $0)-XXXXXXX`
STATUS=`mktemp -t $(basename -s .sh $0)-XXXXXXX`
trap " /bin/rm -fr $TMP $STATUS" INT QUIT EXIT HUP KILL ALRM
# User name for label computed as in elastic_blast.elb_config.create_labels
user=$(echo $username | tr '[A-Z-]' '[a-z_]' | tr '.' '-' | cut -b-62)
gcloud container clusters list --filter=resourceLabels.owner=$user --format='value(resourceLabels.results,resourceLabels.created)' | sort > $TMP
[ -s $TMP ] && {
echo "These are your ElasticBLAST searches on GCP that have not been deleted";
echo "Please note that the results bucket names below been modified to remove upper case and all '/' characters following 'gs://'";
}
while read -r r c; do
results=$(echo $r | sed 's,---,://,')
created=$(echo $c | sed 's/-/ /3;s/-/:/4;s/-/:/3')
# FIXME: how to restore original results bucket name?
#if [[ "$r" =~ "elasticblast-$user" ]]; then
# results=$(echo $r | sed "s,---,://,;s,$user,$user/,")
#fi
echo "##### Results bucket: $results"
echo "##### Created: $created UTC"
#echo "##### Status:"
#elastic-blast status --results $results | tee $STATUS
#check_status $results "$created" $STATUS
done < $TMP