Mark Muyskens
11-18-2009, 02:44 AM
Exactly what the subject says, I'd like as many suggestions as possible. :agree:
Thanks!
#!/bin/bash
# Mark's Health Check
# Mark Muyskens
# mmuyskens@gmail.com
# Released under whatever the hell license you want
DMOUNT="/dev/sda1"
LDISKSPACEGB="10"
LMEMMB="100"
SUBJECT="Health Check for Server `hostname -f`"
EMAIL="mmuyskens@gmail.com"
EMAILMESSAGE="/tmp/emailmessage.txt"
ALERT="/tmp/alert.txt"
STATS="/tmp/stats.txt"
mstotal=$(free -tom | grep "Total:" | awk '{print $2}')
msused=$(free -tom | grep "Total:" | awk '{print $3}')
msfree=$(free -tom | grep "Total:" | awk '{print $4}')
mtotal=$(free -om | grep "Mem:" | awk '{print $2}')
mused=$(free -om | grep "Mem:" | awk '{print $3}')
mfree=$(free -om | grep "Mem:" | awk '{print $4}')
uptime=$(uptime | awk '{print $3}')
load=$(uptime | awk '{print $11}' | sed 's/,//')
tdisk=$(df -h | grep "$DMOUNT" | awk '{print $2}')
udisk=$(df -h | grep "$DMOUNT" | awk '{print $3}')
adisk=$(df -h | grep "$DMOUNT" | awk '{print $4}')
adisksed=$(df -h | grep "$DMOUNT" | awk '{print $4}' |sed 's/G//')
pdisk=$(df -h | grep "$DMOUNT" | awk '{print $5}')
echo "Total memory (including swap): $mstotal MB" >$STATS
echo "Used memory (includeing swap): $msused MB" >>$STATS
echo "Free memory (includeing swap): $msfree MB" >>$STATS
echo "Total memory (excluding swap): $mtotal MB" >>$STATS
echo "Used memory (excluding swap): $mused MB" >>$STATS
echo "Free memory (excluding swap): $mfree MB" >>$STATS
echo "Server Uptime: $uptime Days" >>$STATS
echo "Server Load: $load" >>$STATS
echo "Total Disk: $tdisk" >>$STATS
echo "Used Disk: $udisk" >>$STATS
echo "Avaliable Disk: $adisk" >>$STATS
echo "Percentage Disk Used: $pdisk" >>$STATS
if [ "$adisksed" -lt "$LDISKSPACEGB" ] || [ "$adisksed" -eq "$LDISKSPACEGB" ]
then
echo -e "Please check server `hostname -f` \nCurrent available disk quota is: $adisk \n" > $ALERT
cat $ALERT $STATS > $EMAILMESSAGE
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
fi
if [ "$mfree" -lt "$LMEMMB" ] || [ "$mfree" -eq "$LMEMMB" ]
then
echo -e "Please check server `hostname -f` \nCurrent available memory is: $mfree MB \n" > $ALERT
cat $ALERT $STATS > $EMAILMESSAGE
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
fi
rm -rf $EMAILMESSAGE
rm -rf $STATS
rm -rf $ALERT
Thanks!
#!/bin/bash
# Mark's Health Check
# Mark Muyskens
# mmuyskens@gmail.com
# Released under whatever the hell license you want
DMOUNT="/dev/sda1"
LDISKSPACEGB="10"
LMEMMB="100"
SUBJECT="Health Check for Server `hostname -f`"
EMAIL="mmuyskens@gmail.com"
EMAILMESSAGE="/tmp/emailmessage.txt"
ALERT="/tmp/alert.txt"
STATS="/tmp/stats.txt"
mstotal=$(free -tom | grep "Total:" | awk '{print $2}')
msused=$(free -tom | grep "Total:" | awk '{print $3}')
msfree=$(free -tom | grep "Total:" | awk '{print $4}')
mtotal=$(free -om | grep "Mem:" | awk '{print $2}')
mused=$(free -om | grep "Mem:" | awk '{print $3}')
mfree=$(free -om | grep "Mem:" | awk '{print $4}')
uptime=$(uptime | awk '{print $3}')
load=$(uptime | awk '{print $11}' | sed 's/,//')
tdisk=$(df -h | grep "$DMOUNT" | awk '{print $2}')
udisk=$(df -h | grep "$DMOUNT" | awk '{print $3}')
adisk=$(df -h | grep "$DMOUNT" | awk '{print $4}')
adisksed=$(df -h | grep "$DMOUNT" | awk '{print $4}' |sed 's/G//')
pdisk=$(df -h | grep "$DMOUNT" | awk '{print $5}')
echo "Total memory (including swap): $mstotal MB" >$STATS
echo "Used memory (includeing swap): $msused MB" >>$STATS
echo "Free memory (includeing swap): $msfree MB" >>$STATS
echo "Total memory (excluding swap): $mtotal MB" >>$STATS
echo "Used memory (excluding swap): $mused MB" >>$STATS
echo "Free memory (excluding swap): $mfree MB" >>$STATS
echo "Server Uptime: $uptime Days" >>$STATS
echo "Server Load: $load" >>$STATS
echo "Total Disk: $tdisk" >>$STATS
echo "Used Disk: $udisk" >>$STATS
echo "Avaliable Disk: $adisk" >>$STATS
echo "Percentage Disk Used: $pdisk" >>$STATS
if [ "$adisksed" -lt "$LDISKSPACEGB" ] || [ "$adisksed" -eq "$LDISKSPACEGB" ]
then
echo -e "Please check server `hostname -f` \nCurrent available disk quota is: $adisk \n" > $ALERT
cat $ALERT $STATS > $EMAILMESSAGE
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
fi
if [ "$mfree" -lt "$LMEMMB" ] || [ "$mfree" -eq "$LMEMMB" ]
then
echo -e "Please check server `hostname -f` \nCurrent available memory is: $mfree MB \n" > $ALERT
cat $ALERT $STATS > $EMAILMESSAGE
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
fi
rm -rf $EMAILMESSAGE
rm -rf $STATS
rm -rf $ALERT
