-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgetInstancesIPs.sh
executable file
·50 lines (39 loc) · 1.14 KB
/
getInstancesIPs.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
#!/bin/bash
# Lists IP addresses of instances in defined region
STOCKHOLM_INSTANCES_IPS_FILE="STOCKHOLM_INSTANCES_IPS.txt"
FRANKFURT_INSTANCES_IPS_FILE="FRANKFURT_INSTANCES_IPS.txt"
main(){
[[ ${#} < 1 ]] &&
echo -e "Stockholm:\n`listStockholm`\n" &&
echo -e "Frankfurt:\n`listFrankfurt`\n" &&
exit 0
for p in ${@}
do
[[ ${p} == "-sf" || ${p} == "-fs" ]] &&
listStockholm && listFrankfurt && exit 0
[[ ${p} == "-s" || ${p} == "--stockholm" ]] && listStockholm
[[ ${p} == "-f" || ${p} == "--frankfurt" ]] && listFrankfurt
[[ ${p} == "-h" || ${p} == "--help" ]] && help
done
exit 0
}
listStockholm(){
listIPs ${STOCKHOLM_INSTANCES_IPS_FILE} "eu-north-1"
}
listFrankfurt(){
listIPs ${FRANKFURT_INSTANCES_IPS_FILE} "eu-central-1"
}
listIPs(){
touch ${1}
local LIST=`aws ec2 describe-instances \
--region ${2} \
--query "Reservations[*].Instances[*].{a:PublicIpAddress}" \
--filters "Name=instance-state-code,Values=16" \
--o text`
echo $LIST > ${1}
[[ -z ${LIST} ]] && echo " There are no IPs" || echo "${LIST}"
}
help(){
echo "Usage: ${0} [-s | --stockholm] [-f | --frankfurt]"
}
./checkAWS.sh && main ${@} || ./awsCliNa.sh