Skip to content

Instantly share code, notes, and snippets.

@maxkramer
Last active December 16, 2015 00:49
Show Gist options
  • Save maxkramer/5350713 to your computer and use it in GitHub Desktop.
Save maxkramer/5350713 to your computer and use it in GitHub Desktop.
Daily server reporting via email. Make sure you add a cron job to run it, and edit all of the email addresses! e.g. 59 23 * * * /home/max/dailyreport.sh > /dev/null 2>&1
#!/bin/bash
apt-get update
(
echo To: emailtosendreportto@gmail.com
echo From: reporting@`hostname`
if [ "$( df -h | grep hda1 | cut -c40-42)" -ge "80" ]; then echo Subject: Production Server : Low Disk Space : Daily reporting for `date +%e\ %B\ %Y`
else echo Subject: Production Server: Daily reporting for `date +%e\ %B\ %Y`
fi
echo Reporting of Production Server: `hostname`
echo
echo Disk Usage:
df | awk 'FNR==2{printf "Using %0.2fGB (%s) of %0.2fGB", $3/1048576, $5, $2/1048576}'
echo
echo
echo Memory:
free | grep Mem | awk '{printf "%0.0f%% in use %0.0f%% free", $3/$2 * 100.0, $4/$2 * 100}'
echo
echo
echo CPU Usage:
mpstat | awk 'FNR==4 {printf "%0.2f%% in use %0.2f%% free", 100 - $12, $12}'
echo
echo
echo Uptime :
uptime | awk '{split($3,a,":");c= a[1] " hours";split(a[2],b,",");print c " " b[1] " minutes"}'
echo
echo Necessary updates:
echo
apt-get -s upgrade
) | /usr/sbin/sendmail -f from@email.com to@email.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment