Skip to content

Instantly share code, notes, and snippets.

@rafaelp
Created December 1, 2013 21:14
Show Gist options
  • Save rafaelp/7740873 to your computer and use it in GitHub Desktop.
Save rafaelp/7740873 to your computer and use it in GitHub Desktop.
Show swap usage
#!/bin/sh
free -m | grep Swap | while read output;
do
swap=$(echo $output | awk '{print $2}' )
used=$(echo $output | awk '{ print $3 }' )
freed=$(echo $output | awk '{ print $4 }' )
echo "Swap : $swap"
echo "Used : $used"
echo "Free : $freed"
usep=`expr $used \* 100 / $swap`
echo $usep
if [ $usep -ge 70 ]; then
echo "Swap Usage Alert Total Swap: \"$swap\" Used: \"$used ($usep%)\" Free:
\"$freed\" on $(hostname) as on $(date)" |
mail -s "Alert: Swap Usage space $usep%" mail1@example.com,mail2@example.com
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment