[Linux]Having a daily report of servers by mail
The monitoring and administration of Linux systems is a very difficult task when there is large number of interconnected servers, system resources and updates to each of them it,must continually monitored.
The following script creates a daily report intended to be sent by mail to the administrator.
Report content: Hard disk status and updates necessary (for Debian based system).
For other systems you must adapt to the existing systems management packages.
#!/bin/bash
apt-get update
(
echo To: receiver@domain.ext
echo From: system@domain.net
if [ "$( df -h | grep hda1 | cut -c40-42)" -ge "80" ]; then echo Subject: Reporting of `date +%e\ %B\ %Y` : LOW DISK SPACE
else echo Subject: Daily reporting of `date +%e\ %B\ %Y` for `hostname`
fi
echo Reporting of `hostname`
echo Disk used :
echo
df -h
echo
echo Server charge :
echo
uptime
echo
echo Necessary updates
echo
apt-get -s upgrade
) | /var/qmail/bin/qmail-inject -fsenderr@domaine.ext receiver@domaine.ext
The above script will display a warning in the message if the hda1 disc has a filling rate greater than 80%. The messaging system used for sending in the example is qmail, but any other similar command (eg / usr / sbin / sendmail) can be used.
To make the script executable:
chmod +x /home/user/script/dailyreport.sh
Finally, creating an entry in the crontab will send daily by mail message (e.g. below 5:00 am):
crontab –e
Insert the following command line:
00 5 * * * /home/user/script/dailyreport.sh > /dev/null 2>&1