Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrichardsz/76c3dce09653828d12a8c48c6b579b4e to your computer and use it in GitHub Desktop.
Save jrichardsz/76c3dce09653828d12a8c48c6b579b4e to your computer and use it in GitHub Desktop.
linux shell snippets
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