文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>mysql审计脚本

mysql审计脚本

时间:2009-06-23  来源:sinxadmin

#1/bin/bash


#parameters


print_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 "++++++++++++++++++++++++++++++++"

}

# getopt

while getopts :ldu:f: myarg
do
    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

#function


get_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

#main

check_option

相关阅读 更多 +
排行榜 更多 +
空中跑酷汉化版

空中跑酷汉化版

赛车竞速 下载
修仙传说

修仙传说

角色扮演 下载
魔界零之迷宫

魔界零之迷宫

冒险解谜 下载