#!/bin/bash # Christopher Jones # logsearch.sh # 02/07/12 # This Script searches the logs for a specified item then executes a specified command. # # Syntax is as follows: # logsearch.sh {"What your searching for"} {command} # # Examples: # logsearch.sh testing "echo 'testing found in logs'" # logsearch.sh unplugged /bin/usr/emailunplug.sh LOGFILE=/var/log/messages ## Log file to use FOUND=N ## Variable used in loop until [ $FOUND = Y ]; do FIND=$( tail -n1 $LOGFILE | grep -i $1 ) ## Searchs log file for specified entry. #echo "$FIND" ## Used for testing SEARCH=${#FIND} if [ $SEARCH -gt 4 ]; then echo "Found $1 in $LOGFILE." >> $LOGFILE echo "Executing $2" >> $LOGFILE $2 FOUND=Y fi done