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.

  1. Kostas
    March 3, 2011 at 4:06 pm

    Hello,

    This is awesome.

  2. Wannes Van Loock
    April 28, 2011 at 11:24 am

    Which are the right permissions for the script ?

    • April 28, 2011 at 12:47 pm

      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)

  3. Kostas
    April 28, 2011 at 1:15 pm

    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

    • April 29, 2011 at 4:16 pm

      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

  4. April 28, 2011 at 1:42 pm

    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

  5. April 28, 2011 at 2:10 pm

    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.

  6. Kostas
    April 28, 2011 at 2:27 pm

    Awesome. Thanks a lot for your efforts!

    Kostas

  7. Kostas Backas
    May 1, 2012 at 11:35 pm

    Hello!
    Is there a way of having CrashPlan reports in the script?

    Best regards

    Kostas

  1. April 29, 2011 at 2:59 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 154 other followers

%d bloggers like this: