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.
: Hard disk status and updates necessary (for Debian based system).
For other systems you must adapt to the existing systems management packages.
echo To: email@example.com
echo From: firstname.lastname@example.org
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`
echo Reporting of `hostname`
echo Disk used :
echo Server charge :
echo Necessary updates
apt-get -s upgrade
) | /var/qmail/bin/qmail-inject -email@example.com firstname.lastname@example.org
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):
- Insert the following command line:
00 5 * * * /home/user/script/dailyreport.sh > /dev/null 2>&1