a unix script cmd Kevin McDonald (liv...

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

Posted in the Maumelle Forum

Since: Feb 13

Irving, TX

#1 Feb 3, 2013
#!/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/local/scripts/m onitor.conf
SCRIPTDIR=`grep "SCRIPTDIR" $CONF_FILE | awk -F='{print $NF}'`

LOCK=/tmp/${LOGNAME}.mon_new_f ile.lock
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=$SCRIPTDIR/monitorNEW Files
#IGNORE_LIST=$ADMINDIR/ignore. List

[email protected]

# 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}_${ LOGNAME}_${DIR_ID}_mon_new_fil e.log"
OLD_LOG="/tmp/${SRVNM}_${ LOGNAME}_${DIR_ID}_mon_new_fil e.old"
DIFF_FILE="/tmp/${SRVNM}_ ${LOGNAME}_${DIR_ID}_mon_new_f ile.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_LIST})" | 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}
jack stringert

Irving, TX

#2 Feb 3, 2013
Neat code!!!

how about?

process, hide, delay, all over again ...

Quote:
# place to put "processed" files
[-d prok.d ]|| mkdir prok.d
# loop
while true
do
# search for *.xx
for this in *.xx
do
# process
str_xx -i $this
# hide it (to avoid re-processing)
mv $this prok.d
done
# rest for 1 minute
sleep 60
done
ziggy

Dallas, TX

#3 Feb 5, 2013
cool code!!
sure fire

Dallas, TX

#4 Feb 9, 2013
good code
harris

Dallas, TX

#5 Feb 9, 2013
neat

Tell me when this thread is updated:

Subscribe Now Add to my Tracker

Add your comments below

Characters left: 4000

Please note by submitting this form you acknowledge that you have read the Terms of Service and the comment you are posting is in compliance with such terms. Be polite. Inappropriate posts may be removed by the moderator. Send us your feedback.

Maumelle Discussions

Title Updated Last By Comments
Because you are the one reading this 50 min Read it and weep 3
Mesical malpractice attorney Tue Dream on 2
Democrats are Corrupt Tue Guest 1
News Man arrested after car hit boy trying to board bus Jan 10 Powerwraith 2
News Caterpillar might end production in Aurora Jan 6 Longhaul 1
Review: LSC Promos Jan 5 bigfoot 2
News The 25 Most Dangerous Cities in the U.S. Are Mo... (Nov '10) Jan 3 Now_What- 20,767

Maumelle Jobs

More from around the web

Personal Finance

Maumelle Mortgages