Howto monitor AWS EC2 instance status in bash script

Task: Monitor instance status in bash script

Implementation:

#!/bin/bash

instanceID=i-...  # your instance ID

# Get instance status...
instanceStatus=$(aws ec2 describe-instance-status --region us-east-1 --instance-ids $instanceID --query 'InstanceStatuses[0].InstanceStatus.Details[0].Status' --output text)
echo "Instance status: $instanceStatus"
if [ $instanceStatus == passed ]; then 
    echo "Instance check status passed..."
fi

# Get system status...
systemStatus=$(aws ec2 describe-instance-status --region us-east-1 --instance-ids $instanceID --query 'InstanceStatuses[0].SystemStatus.Details[0].Status' --output text)
echo "System status: $systemStatus"
if [ $systemStatus == passed ]; then 
    echo "System check status passed..."
fi

This script contain two checks: first for instance status and second for system status.

Done.

Leave a Reply

Your email address will not be published. Required fields are marked *




Enter Captcha Here :