Created
January 11, 2018 07:05
-
-
Save namnv609/4003bda2a65eb2f9e78325fdd3aa9010 to your computer and use it in GitHub Desktop.
Check server (Amazon EC2) meminfo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Created by NamNV609 | |
read -p "Please enter host username (ec2-user): " ipUsername | |
read -p "Please enter host IP address: " ipAddr | |
ipUsername=${ipUsername:-"ec2-user"} | |
echo "Execute command: ssh $ipUsername@$ipAddr cat /proc/meminfo | awk 'NR < 3 {print}'" | |
echo "Meminfo of $ipAddr:" | |
meminfo=$(ssh "$ipUsername"@"$ipAddr" cat /proc/meminfo | awk 'NR < 3 {print}') | |
memTotal=$(echo -e "$meminfo" | awk 'NR==1{print $2}') | |
memFree=$(echo -e "$meminfo" | awk 'NR==2{print $2}') | |
echo -e "$meminfo\n------------------------------\nMemTotalInMB:\t $(($memTotal / 1024))\tMB\nMemFreeInMB:\t $(($memFree / 1024))\tMB" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment