forked from lokeshkamalay/DevOps-References
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws.sh
20 lines (16 loc) · 847 Bytes
/
aws.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh
echo "Getting the instance id here"
InstanceID=$(aws ec2 describe-instances --filter Name=tag:Name,Values=sq.com --query Reservations[].Instances[].InstanceId | grep -vE '\[|\]' | awk -F'"' '{ print $2 }')
echo "Current status of the instance $InstanceID"
C_STATUS=$(aws ec2 describe-instances --instance-id $InstanceID --query Reservations[].Instances[].State[].Name | grep -vE '\[|\]' | awk -F'"' '{ print $2 }')
if [[ $C_STATUS == "running" ]]; then
echo "The instance is running, stopping it now"
aws ec2 stop-instances --instance-ids $InstanceID
if [[ $? == 0 ]];then
echo "Instance is stopped successfully"
else
echo "There seems to be a problem in stopping the instance, pls do it manually"
fi
else
echo "The machine is not in running status"
fi