zoukankan      html  css  js  c++  java
  • [原创]实现MongoDB数据库审计SQL语句的脚本

    功能:实现具体显示mongodb数据库表操作语句的状态和情况,使用awk和shell实现抓取和分析处理。脚本内容如下:


    #!/bin/bash

    if [ $# == 0 ];then

    echo "NO enter any worlds,Please enter three worlds, the first world is db and the second world is collection and last world is host for statics!"

    elif [ $# == 1 ];then

    echo "Enter a world,Please enter other two worlds, the first world is db and the second world is collection and last world
    is host for statics!"

    elif [ $# == 2 ];then

    echo "Enter two worlds,Please enter another worlds, the first world is db and the second world is collection and last world
    is host for statics!"

    elif [ $# == 3 ];then

    world=$1.$2
    date=`date +%Y%m%d%H%M%S`
    cd /data/Darren/mongodb2.6/bin/
    ./mongoexport --host $3 --db $1 --collection system.profile --out /data/Darren/mongo_statics/dump_$3_${date}.json
    cd /data/Darren/mongo_statics/
    grep op dump_$3_${date}.json | awk -F ":|[,]" '{if($4 ~/"'$world'"/) {print}}' >> /data/Darren/mongo_statics/$3_${world}_${date}.log
    cat $3_${world}_${date}.log | awk -F ":|[,]|[{]" '{if($8 ~/ "$query" /){$8=$10}if($3 ~/ "insert" /){$8=$6}}{print $5,$3,$8}' | awk -F '"' 'BEGIN{OFS=" | "}{print $2,$4,$6}'|sort|uniq -c >> /data/Darren/mongo_statics/result_$3_${world}_${date}.txt
    cat result_$3_${world}_${date}.txt

    else

    echo "Please enter the correct worlds number!"

    fi
  • 相关阅读:
    Thread.join
    Thread.yield
    线程的生命周期
    HashMap底层原理
    Web Services
    Struts2框架
    hibernate乐观锁实现原理
    Hibernate框架
    oracle exp 无法导出空表
    linux 远程复制文件或文件夹
  • 原文地址:https://www.cnblogs.com/wsjhk/p/6909422.html
Copyright © 2011-2022 走看看