Created
June 18, 2022 00:27
-
-
Save jrichardsz/76c3dce09653828d12a8c48c6b579b4e to your computer and use it in GitHub Desktop.
linux shell snippets
This file contains 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
now=$(date '+%Y-%m-%d_%H-%M-%S') | |
free_ram=$(free -h | awk '/^Mem:/{print $4}') | |
cpu_usage=$(grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}') | |
response_code=$(curl -s -o /dev/null -w "%{http_code}" localhost:8080/login) | |
if [[ "$response_code" -ne "200" ]]; then | |
echo "$now foo http is down with code:$response_code free_ram:$free_ram cpu_usage:$cpu_usage " >> /home/ubuntu/restart.log | |
shutdown -r | |
else | |
echo "$now foo http is up with code:$response_code free_ram:$free_ram cpu_usage:$cpu_usage" >> /home/ubuntu/restart.log | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment