Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MCX debug reporting script
#!/bin/sh
PATH=/bin:/usr/bin:/sbin:/usr/sbin export PATH
# Define the recipient.
RECIP="email@address.here"
# That should be it for the necessary configuration part. The rest can be pretty much as-is.
NAME=`hostname`
LOGS="/tmp/tomcat-restart.txt"
HWLOGDATE=$(printf "`date "+%a %h %e"` \n")
SEND="mcx_debug@`hostname`"
# Activate MCX debug logging
/usr/bin/defaults write /Library/Preferences/com.apple.MCXDebug debugOutput -2
/usr/bin/defaults write /Library/Preferences/com.apple.MCXDebug collateLogs 1
# Now begin writing the daily report.
echo "From: MCX Debug Report <$SEND>" > $LOGS
echo "To: $RECIP" >> $LOGS
echo "Subject: $NAME MCX Debug Report Report" - `date` >> $LOGS
ADDY=`ifconfig eth1 |grep "inet addr" |awk '{print $2}' |awk -F: '{print $2}'`
# Give an introduction.
echo "***********************************************************************" >> $LOGS
echo "***** Hi. You're receiving this because you want MCX debug reports" >> $LOGS
echo "***** This is the report for `date "+%a %h %e"`. " >> $LOGS
echo "***** Report is for `hostname` ($ADDY). " >> $LOGS
echo "***********************************************************************" >> $LOGS
echo " " >> $LOGS
echo " " >> $LOGS
# This tails /Library/Logs/ManagedClient/ManagedClient.log and hopefully catches the errors
echo "Last 500 Lines of the ManagedClient log" >> $LOGS
echo "--------------------------------" >> $LOGS
tail -500 /Library/Logs/ManagedClient/ManagedClient.log >> $LOGS
echo " " >> $LOGS
echo " " >> $LOGS
# Read LOGS, pipe it to sendmail and fire off an email.
cat $LOGS | sendmail -f $RECIP -t
# Get rid of the files.
rm $LOGS
# Deactivate MCX debugging
/bin/rm /Library/Preferences/com.apple.MCXDebug.plist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment