#!/bin/sh # #NADDS Agent - http://nadds.drmadcow.net/ #Critical file change agent. #Agent Author: Daryl Quenet #Date: 2003-May-27 (V1.5) . /usr/local/bcnu/etc/bcnuenv . $BCNUHOME/agent/agent_head OUTFILE=$BCNUTMP/${BCNUAGENT}.out MSGFILE=$BCNUTMP/${BCNUAGENT}.msg ERR_MSG_FILE=$BCNUTMP/${BCNUAGENT}.err HISTFILE=$BCNUTMP/${BCNUAGENT}.hist rm -f $TMPFILE $HISTFILE $ERR_MSG_FILE $OUTFILE $MSGFILE 2>/dev/null if [ ! -d $BCNUHOME/data/${BCNUAGENT}-archive ]; then mkdir -p $BCNUHOME/data/${BCNUAGENT}-archive fi ERR="" WARN="" MSG="" ERRMSG="" WARNMSG="" for param in $BCNUPARAM do bcnu_param filename=$p1 filehandle=$p2 if [ ! -f $BCNUHOME/data/${BCNUAGENT}-archive/$filehandle ]; then cp -p $filename "${BCNUHOME}/data/${BCNUAGENT}-archive/$filehandle" if [ ! -f "${BCNUHOME}/data/${BCNUAGENT}-archive/$filehandle" ]; then WARNMSG="warning - $filename is not being monitored. Check file permissions/spelling" echo $WARNMSG >> $ERR_MSG_FILE WARN=1 else MSG="$filename is now being monitored." echo $MSG >>$MSGFILE fi fi fileperm=`ls -l $filename|awk '{print $1}'` filehperm=`ls -l "$BCNUHOME/data/${BCNUAGENT}-archive/$filehandle"|awk '{print $1}'` diff "$filename" $BCNUHOME/data/${BCNUAGENT}-archive/$filehandle 2> /dev/null if [ $? = 1 ]; then ERRMSG="error - Contents of $filename have changed, original backed up" timestamp=`date +%Y%m%d%H%M%S` namedtime="${filehandle}_${timestamp}" cd $BCNUHOME/data/${BCNUAGENT}-archive/ tar cfpz "$namedtime".tgz $filehandle rm -f "$BCNUHOME/data/${BCNUAGENT}-archive/$filehandle" cp -p $filename "$BCNUHOME/data/${BCNUAGENT}-archive/$filehandle" echo $ERRMSG >>$ERR_MSG_FILE if [ ! -f $MSGFILE ]; then touch $MSGFILE fi ERR=1 echo -e "\t$namedtime" >>$HISTFILE elif [ $fileperm != $filehperm || -f $filename]; then ERRMSG="error - ${filename}s permissions have changed from $filehperm to ${fileperm}" echo $ERRMSG >>$ERR_MSG_FILE if [ ! -f $MSGFILE ]; then touch $MSGFILE fi ERR=1 else if [ -f $BCNUHOME/data/${BCNUAGENT}-archive/$filehandle ]; then MSG="ok - $filename is intact" echo $MSG >>$MSGFILE fi fi done if [ -f $MSGFILE ]; then printf "File status:\n\n" > $OUTFILE if [ -f $ERR_MSG_FILE ]; then sort_by_severity '-k 1' $ERR_MSG_FILE >> $OUTFILE fi sort_by_severity '-k 1' $MSGFILE >> $OUTFILE fi if [ -f $HISTFILE ]; then hostname=`hostname` printf "\nNewly archived files in ${hostname}:${BCNUHOME}/data/${BCNUAGENT}-archive\n" >>$OUTFILE cat $HISTFILE >>$OUTFILE fi if [ $ERR ]; then BCNUMSG="$BCNU -m '$ERRMSG' -f $OUTFILE -e $BCNU_ERR -t $BCNUHOSTTYPE $BCNUHOST" bcnu_err_send elif [ $WARN ]; then BCNUMSG="$BCNU -m '$WARNMSG' -f $OUTFILE -e $BCNU_WARN -t $BCNUHOSTTYPE $BCNUHOST" bcnu_warn_send else BCNUMSG="$BCNU -m 'ok - no critical files have changed' -f $OUTFILE -e $BCNU_OK -t $BCNUHOSTTYPE $BCNUHOST" bcnu_send fi