Tuesday, March 18, 2014

Linux Command line operation Auditing script

Hi, do you want to log all linux operation in a file for auditing purpose..Yeah

then look below for script

#!/bin/sh

if [ -z "$1" ];
then
        echo "Please input Operation ID !"
        exit
fi

LOGDIR=/LOCATION for SAVING LOG/operation_log_svr/`date +%d`/`date +%m`/`date +%Y`
OPID=$1
echo "Start log for ${OPID} "
echo "Store log at ${LOGDIR}/${OPID}"

test -d ${LOGDIR}         || mkdir -m 2775 ${LOGDIR}
test -d ${LOGDIR}/${OPID} || mkdir -m 2775 ${LOGDIR}/${OPID}

if [ -d ${LOGDIR}/${OPID} ];
then
        while [ -f ${LOGDIR}/${OPID}/log.`date +%d%m%Y-%H%M%S` ]
        do
                sleep 1
        done
        script -a ${LOGDIR}/${OPID}/log.`date +%d%m%Y-%H%M%S`
        echo "Your log at"
        echo "${LOGDIR}/${OPID}/"
        ls -l     ${LOGDIR}/${OPID}/
        echo "================Target List=================="
        for _log in `ls ${LOGDIR}/${OPID}/`;do egrep "^Connection to " ${LOGDIR}/${OPID}/${_log};done |sort
else
        echo "Directory not ready !"
        exit
fi

No comments:

Post a Comment