Send a Message
to aaawest10

Comments

2

Joined

Feb 3, 2013

aaawest10 Profile

Forums Owned

Recent Posts

Little Rock, AR

a unix script cmd Kevin McDonald (lives in Little Rock)

#!/bin/ksh # # UNIX Monitor New File Script # Purpose: Monitors the new files in a directory # Notifies via e-mail # Outputs: Email # Author : Steven Koh #***************** ****************** ****************** **** # if test $# -lt 1; then echo "Usage: $0 <DIR TO MONITOR FOR NEW FILES> <FILENAME to exclude, delimited by |>" echo "Example: $0 /var/tmp \"Test1|Test2 \"" echo exit 0; fi MONITOR_DIR=$1 IGNORE_LIST=$2 OS=`uname -s` CONF_FILE=/usr/loc al/scripts/monitor .conf SCRIPTDIR=`grep "SCRIPTDIR " $CONF_FILE | awk -F= '{print $NF}'` LOCK=/tmp/${LOGNAM E}.mon_new_file.lo ck if test -f $LOCK; then echo "${LOCK} exists. Exiting this job now ... " | mailx -s "$0" ${LOGNAME} exit fi touch ${LOCK} # The directory this script resides in ADMINDIR=$SCRIPTDI R/monitorNEWFiles #IGNORE_LIST=$ADMI NDIR/ignore.List MAILADD=${LOGNAME} @localhost # Define the hostname of the server SRVNM=`uname -n` # Define the hostname of the SNMP server SNMP_SRV=`grep "SNMP_SRV " $CONF_FILE | awk -F= '{print $NF}'` SEND_TRAP=`grep "SEND_TRAP " $CONF_FILE | awk -F= '{print $NF}'` echo ${MONITOR_DIR} DIR_ID=`echo ${MONITOR_DIR} | sed 's/\//_/'g` NEW_LOG="/tmp /${SRVNM}_${LOGNAM E}_${DIR_ID}_mon_n ew_file.log" OLD_LOG="/tmp /${SRVNM}_${LOGNAM E}_${DIR_ID}_mon_n ew_file.old" DIFF_FILE="/t mp/${SRVNM}_${LOGN AME}_${DIR_ID}_mon _new_file.same " touch ${NEW_LOG} mv ${NEW_LOG} ${OLD_LOG} echo "============ = `date` ============= " | tee $NEW_LOG unalias ls ls -tr ${MONITOR_DIR} | tee -a ${NEW_LOG} if test $# -eq 1; then egrep -vf ${OLD_LOG} ${NEW_LOG} | grep -v "============ =" > ${DIFF_FILE} 2>&1 else egrep -vf ${OLD_LOG} ${NEW_LOG} | egrep -v "(${IGNORE_LI ST})" | grep -v "============ =" > ${DIFF_FILE} 2>&1 fi if test `wc -l < ${DIFF_FILE}` -gt 0; then echo "UNIX Monitor New Files - Monitor new files in ${MONITOR_DIR} " echo "New Files for past 2 runs" echo "============ ================== ====" echo cat ${DIFF_FILE} echo ################ ### Sending Mail mail ${MAILADD} <<EOF From: $0 To: $MAILADD Subject: UNIX Monitor New Files - Monitor new files in ${MONITOR_DIR} New Files for past 2 runs ================== ================ `cat ${DIFF_FILE}` EOF fi rm ${LOCK}  (Feb 3, 2013 | post #1)