#!/bin/bash
# Aayush Tuladhar
# v1.0 (2011)
# DistCC Monitor
# Performs Distcc On the Host Servers. Gets the compilation time and delivers email using sendmail.
HOSTFILE=/usr/local/itasca/buildtools/etc/lsdistcc_hosts
sendmailbin=/usr/sbin/sendmail
WORKING_DIR=`pwd`
MAIL_LIST_FILENAME=maillist.txt
REPORTFILENAME=$(date +"%b_%e_%Y"_report.txt)
REPORTFILE=$WORKING_DIR/$REPORTFILENAME
MAIL_LIST=$WORKING_DIR/$MAIL_LIST_FILENAME
SERVER_STATUS=0 #0 - No Server Down #1 - Server Down
#Mail Settings (FROM, SUBJECT, emailtarget, msgdate, daemail)
FROM="distcc_report.mailbot@distccmon.com"
function sendmail(){
if [ -z $SERVER_STATUS ]
then
SUBJECT="Buildfarm Monitor : Server Up"
else
SUBJECT="Buildfarm Monitor : Server Down"
fi
msgdate='date+"%a, %e %Y %T %z"'
daemail=$(cat <> $REPORTFILE
SERVER_STATUS=1
else
echo "Server : $1 [UP]" >> $REPORTFILE
fi
}
echo "$(date)" >> $REPORTFILE
echo "-------------------------------------" >> $REPORTFILE
if [ -r $HOSTFILE ]
then
#Reading Hosts
exec 9<$HOSTFILE
while read -u9 line
do
#Processing Hosts
check_status $line
done
else
echo "Error : HostFile ($HOSTFILE) not Found"
exit 111 #Exit 111 : Hostfile Not Found
fi
#Reading Maillist
if [ -r $MAIL_LIST ]
then
#Reading Maillist
exec 8<$MAIL_LIST
while read -u8 list
do
#Reading List
emailtarget=$list,$emailtarget
done
echo -e "\nSTATUS : Sending Mail to $emailtarget"
sendmail
else
echo "Error : Maillist ($MAIL_LIST) not Found"
exit 112 #Exit 112 : Maillist Not Found
fi