Daily server reports
One of the items that I’ve found and adapted for my own use over the past couple of years has been a script for my servers that emails me a status report on a daily basis. The script tells me a number of things that are good to know, including the following:
Uptime
Free space on all attached drives
Who’s logged in via SSH or in the console (console = logged in via Login Window)
If AFP is running, and who is logged in via AFP
If SMB is running, and who is logged in via SMB
Unsuccessful login attempts via SSH
Unsuccessful attempts to use sudo by accounts not authorized to use sudo
Authorized sudo commands that have been run
Time Machine backup status (10.5.x and 10.6.x only)
Apple Hardware RAID status
XServe hardware monitoring messages
Any available software updates
The script has been written and adapted by a number of folks, including Corey Carson and Noah Abrahamson, and has been really useful in helping me both gather information and diagnose problems on my Mac servers. Since it’s so useful, I’m posting it here for others to use and adapt for their own purposes.
Scripts updated – 4-29-2011. I’ve added a section to the 10.4.x script and the 10.5.x/10.6.x script that checks for and reports on the status of your Apple hardware RAID (this is using Apple’s MEGARAID card on the G5 XServes, or with the Apple RAID card available for the Intel XServes and Mac Pros.) See comments in the script for more details.
http://homepage.mac.com/flounder/server_email_reports_2011.zip
To make this work, you’ll need to edit the script to have it send to whatever email address you want to use. The script is pretty well commented, but please let me know if you’ve got any questions about how it works.
Hello,
This is awesome.
Which are the right permissions for the script ?
For 10.4.x
In /etc/periodic/daily: copy 090.daily.logreport to /etc/periodic/daily
Change permissions on /etc/periodic/daily/090.daily.logreport to match the following:
Owner – root (r/w/x)
Group – wheel (r/x)
Everyone – (r/x)
For 10.5.x – 10.6.x
In /Library/LaunchDaemons: copy com.nhgri.daily_report.plist to /Library/LaunchDaemons
Change permissions on /Library/LaunchDaemons/com.nhgri.daily_report.plist to match the following:
Owner – root (r/w)
Group – wheel (r)
Everyone – (r)
In /Library/: Copy the directory called daily_report_script to /Library. It has a script inside called daily_logreport.sh that generates and emails the nightly report.
Change permissions to match the following:
/Library/daily_report_script/
Owner – root (r/w/x)
Group – admin (r/w/x)
Everyone – (r/x)
/Library/daily_report_script/daily_logreport.sh
Owner – root (r/w/x)
Group – wheel (r/x)
Everyone – (r/x)
How can we check if Time Machine backups are completed successfuly? Now all I get is “Time Machine backups not running”.
Also, we added the following in order to check Apple Raid card:
#Check RAID Condition”
echo “Checking Apple RAID Status!” >> $LOGS
echo “——” >> $LOGS
system_profiler SPHardwareRAIDDataType >> $LOGS
echo ” ” >> $LOGS
echo ” ” >> $LOGS
Regards
Kostas
Thanks for the idea about the RAID card. I’ve added a new section to the script that checks for and reports on Apple RAID cards. For code, see here:
http://www.pastie.org/1847383
If you’re on 10.6, try changing this section from this:
# This checks for Time Machine backup commands.
echo "TIME MACHINE ACTIVITY" >> $LOGS
echo "---------------------" >> $LOGS
if grep -E '/System/Library/CoreServices/backupd' /var/log/system.log | grep "backup" > /dev/null
then
grep -E '/System/Library/CoreServices/backupd' /var/log/system.log | grep "backup" >> $LOGS
echo " " >> $LOGS
echo " " >> $LOGS
else
echo "Time Machine backups not running." >> $LOGS
echo " " >> $LOGS
echo " " >> $LOGS
fi
To this:
# This checks for Time Machine backup commands.
echo "TIME MACHINE ACTIVITY" >> $LOGS
echo "---------------------" >> $LOGS
if grep -E 'com.apple.backupd' /var/log/system.log | grep "backup" > /dev/null
then
grep -E 'com.apple.backupd' /var/log/system.log | grep "backup" >> $LOGS
echo " " >> $LOGS
echo " " >> $LOGS
else
echo "Time Machine backups not running." >> $LOGS
echo " " >> $LOGS
echo " " >> $LOGS
fi
Found a better way to update the script so that you don’t have to have different scripts for 10.5 and 10.6:
# This checks for Time Machine backup commands.
echo "TIME MACHINE ACTIVITY" >> $LOGS
echo "---------------------" >> $LOGS
if grep -E 'com.apple.backupd' /var/log/system.log | grep "backup" > /dev/null; then
grep -E 'com.apple.backupd' /var/log/system.log | grep "backup" >> $LOGS
echo " " >> $LOGS
echo " " >> $LOGS
elif grep -E '/System/Library/CoreServices/backupd' /var/log/system.log | grep "backup" > /dev/null; then
grep -E '/System/Library/CoreServices/backupd' /var/log/system.log | grep "backup" >> $LOGS
echo " " >> $LOGS
echo " " >> $LOGS
else
echo "Time Machine backups not running." >> $LOGS
echo " " >> $LOGS
echo " " >> $LOGS
fi
I’ll update the download link above with the changes to the script shortly.
Awesome. Thanks a lot for your efforts!
Kostas
Hello!
Is there a way of having CrashPlan reports in the script?
Best regards
Kostas