Hire me if you like: blake.irvin@gmail.com

Saturday, July 07, 2007

Practical use of 'mail' in BASH

This applies specifically to OS X Server 10.4.8 - changes might be
needed for other systems.


#!/bin/bash

HOST=`hostname`
OS_VERS=`sw_vers | grep ProductVersion`

ROOT_CAPACITY=`df -h / | grep "/" | awk '{print $5}'`
DISK_CAPACITIES=`df -hl | grep "/" | awk '{print $5" "$6}'`
AFP_STATUS=`serveradmin status afp`
SMB_STATUS=`serveradmin status smb`
OD_STATUS=`serveradmin status dirserv`
HTTP_STATUS=`serveradmin status web`
SWUPDATE_STATUS=`serveradmin status swupdate`
NFS_STATUS=`serveradmin status nfs`
SENDMAIL_STATUS=`serveradmin status mail`
UNIX_SNAPSHOT=`w`
RECENT_AUTH_FAILURES=`tail /var/log/secure.log | grep ailed`
RECENT_REBOOTS=`grep reboot /var/log/system.log`
SMART_ERRORS=`system_profiler | grep "S.M.A.R.T." | grep -v
"S.M.A.R.T. status: Verified" | wc -l`

echo "
Host Info
$HOST - $OS_VERS

Drive Space
$DISK_CAPACITIES

AFP
$AFP_STATUS

SMB
$SMB_STATUS

Open Directory
$OD_STATUS

Web Service
$HTTP_STATUS

Software Update Service
$SWUPDATE_STATUS

NFS
$NFS_STATUS

Mail (Sendmail only)
$SENDMAIL_STATUS


--- Additional Details Below ---

Recent Activity:

$UNIX_SNAPSHOT


Recent Authentication Failures:

$RECENT_AUTH_FAILURES


Recent Reboots:

$RECENT_REBOOTS


S.M.A.R.T Errors

$SMART_ERRORS


end transmision..." | mail -s "Status report for $HOST" "user@domain.com"

No comments:

Archive