Novell Home

Have Your Workstation Notify You of Problems

Novell Cool Solutions: Tip
By Randall R. Saeks

Digg This - Slashdot This

Posted: 7 Dec 2005
 

PROBLEM: Having workstations notify someone when they have problems.

SOLUTION: Run a script on a periodic basis to check the system log for problems and if a condition is met, send an email. This could be in an hourly cronjob, for example.

EXAMPLE: Here is the script:

#!/bin/sh
#-= Varibles for auto-notify =-
# Name of the machine
hostname=`hostname -s`
#Search for things in the last hour.
hr_lookup=`date +%h" "%d" "%H:`


# -= Data for auto-notify =-
# Give the IP and network info of the client
network_info=`ifconfig -L en0 | grep broadcast`
# Display the last 5 users.  (Optional)
# change PATH to location of user logins, if #desired
last_usr=`tail -n5 PATH`
#Location of system log, and pull last 1000 lines.
#Search for things in the last hour with the " | #grep $hr_lookup" command.  Remove to look in the 
#last 1000 lines, regardless of time.
#Also, change CONDITION to text that appears in 
#log for the event you want to be notified of, 
#quoted if a longer item.
#EX: crashdump will show all lines with crashdump #in them.  Likewise, "Search Connection Failure" 
#will show all lines with that string.
sys_log=`tail -n1000 /var/log/system.log | grep "$hr_lookup" | grep CONDITION`


# -= Begin Script =-
# If something was found in the log, then prepare #to send an email.  Varibles behave as above.
if tail -n1000 /var/log/system.log | grep "$hr_lookup" | grep CONDITION
then
# change EMAIL to email address
/usr/sbin/sendmail EMAIL <<EOF
# Change LOCALID to what you want the sender to #be.  can be helpful for email filtering.
From: LOCALID
#Change TOEMAIL to who is the email to
To: TOEMAIL
# SUBJECT = Subject of the email
Subject: SUBJECT
#This is the body of the email.  Change with what you want to display.
 -------------------
|Machine name:|
 -------------------
$hostname

 -----------------
|Last 5 Users:|
 -----------------
$last_usr

 -----------------
|Network info:|
 -----------------
$network_info

 ----------------
|System Log:|
 ----------------
$sys_log
EOF
fi
#Make sure to remove comments (lines beginning with '#') between the two EOF's, otherwise, those will be in the body of the email.


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell