心想事成
sinxadmin
全部博文(75)
Python(1)
Java(0)
Perl(6)
Shell(5)
Oracle(32)
Mysql(8)
Solaris(0)
HP(0)
AIX(0)
Linux(16)
2011年(1)
2010年(9)
2009年(65)
cynthia
浪花小雨
hongwent
damoluom
s2t61
分类: LINUX
2009-06-23 15:27:10
#1/bin/bash#parametersprint_help(){ echo "++++++++++++++++++++++++++++++++" echo "mysql audit tool" echo "-l login" echo "-u user " echo "-f mysql log file" echo "sh mysql_audit.sh -l -u root@localhost -f /home/mysql/log/hostname.log" echo "sh mysql_audit.sh -u root@localhost -f /home/mysql/log/hostname.log" echo "sh mysql_audit.sh -d -f /home/mysql/log/hostname.log" exit 1 echo "++++++++++++++++++++++++++++++++"}# getoptwhile getopts :ldu:f: myargdo case $myarg in :) echo "You should specify the argument value" print_help;; l) login=True;; u) user=$OPTARG;; f) file=$OPTARG;; d) denied=True;; *) echo "Unkown argument" print_help;; esac done#functionget_login(){ awk -v temp=$user '$4~/Connect/{a[$3]=($5==temp)?1:0;if(a[$3]){for(i=1;i<=NF;i++){printf $i" "}printf "\n"}} $4~/^Quit$/{if(a[$3]){for(i=1;i<=NF;i++){printf $i" "}printf "\n"}}' /tmp/mysql_audit.log rm -rf /tmp/mysql_audit.log exit 0}get_operation(){ awk -v temp=$user '$4~/^Connect$/{a[$3]=($5==temp)?1:0}(a[$3]==1){for(i=1;i<=NF;i++){printf $i" "}printf "\n"}' /tmp/tlog rm -rf /tmp/mysql_audit.log exit 0 }get_denied(){ awk '$4~/^Connect$/&& $6~/^denied$/' /tmp/mysql_audit.log exit 0}check_option(){ if [ "$login" = "True" -a -n "$user" ];then echo "Date Time User" get_login elif [ -z "$login" -a -n "$user" ];then echo "Date Time ID Command" get_operation elif [ "$denied" = "True" -a -z "$login" ];then echo "Denied" get_denied else print_help fi}grep -Ev '(^Tcp.*Unix|^Time.*Argument$|.*started with:$)' $file |awk --posix '$1~/^[0-9]{6}$/{a=$1" "$2;b=$1" "$2" "$3" "}$1~/^[0-9]{1,3}$/{$0=a$0}$1!~/^[0-9]+$/{$0=b$0}1' >/tmp/mysql_audit.log#maincheck_option
上一篇:linux笔记
下一篇:mysql审计(perl)
登录 注册