[原创]实现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

转载于:https://www.cnblogs.com/wsjhk/p/6909422.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值