当前位置:网站首页>Oracle 脚本实现简单的审计功能
Oracle 脚本实现简单的审计功能
2022-08-03 18:19:00 【墨天轮】
前景
为了数据安全,生产环境开数据库审计的话会有很大的消耗,一般不建议开启。于是根据dba_hist_active_sess_history写了个shell 脚本,每天产生一个简单的审计报告。
审计脚本:audit_db.sh
#!/bin/sh export ORACLE_SID=twoexport ORACLE_UNQNAME=twoexport ORACLE_BASE=/u01/app/oracleexport ORACLE_HOME=/u01/app/oracle/11.2.0.3/productexport PATH=$ORACLE_HOME/bin:$PATHexport LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATHexport NLS_LANG=AMERICAN_AMERICA.AL32UTF8export con_user='sqlplus -s / as dba'export au_dir='/u01/report/audit_db'audit_date=`date +%Y-%m-%d -d "1 day ago"`if [ ! -d ${au_dir}/${audit_date} ];then mkdir -p ${au_dir}/${audit_date}firesult=`$con_user <<EOFset colsep','; set echo off; set feedback off; set heading off; set pagesize 0; set linesize 1000; set numwidth 12; set termout off; set timing off; set trimout on; set trimspool on; set trims on; col username format a15col machine format a30col program format a50col sql_opname format a20spool ${au_dir}/${audit_date}/${audit_date}.txt select to_char(h.sample_time, 'yyyy-mm-dd hh24:mi:ss') exec_time, u.username, h.machine, h.program, h.sql_opname from sys.dba_hist_active_sess_history h left join sys.all_users u on u.user_id = h.user_id where h.module is not null and h.sql_opname is not null and to_char(h.sample_time, 'yyyy-mm-dd') = '$audit_date';spool offEOF`result_report=`$con_user <<EOFset colsep','; set echo off; set feedback off; set heading off; set pagesize 0; set linesize 800; set numwidth 12; set termout off; set timing off; set trimout on; set trimspool on; set trims on; col username format a15col machine format a30col program format a50col sql_opname format a20spool ${au_dir}/${audit_date}/${audit_date}.report select u.username, h.machine, h.program, h.sql_opname, count(*) from sys.dba_hist_active_sess_history h left join sys.all_users u on u.user_id = h.user_id where h.module is not null and h.sql_opname is not null and to_char(h.sample_time, 'yyyy-mm-dd') = '$audit_date' group by username, machine, program, h.sql_opname order by 5 desc;spool offEOF`
输出日志:
[[email protected] 2022-08-02]$ cat 2022-08-02.report业务用户 主机名 连接方式 操作类型 操作次数two ,app.tomcat.com ,JDBC Thin Client ,SELECT, 8610two ,app1.tomcat.com ,JDBC Thin Client ,INSERT, 8610
边栏推荐
猜你喜欢
随机推荐
程序员如何分分钟搞垮一个项目?
大佬,谁有空帮忙看下这个什么问题呢,我就读取MySQLsource print下,刚接触flink,
flink-sql 客户端,咋回事 我show tables 报错
excel写入不完全sheet.append方法(openpyxl)
广告电商、泰山众筹、链动2+1,这3个模式到底怎么样?
关于vscode安装包下载太慢解决方法
es6新增-async函数(异步编程的最终解决方案)
开篇-开启全新的.NET现代应用开发体验
域名抢注“卷”到了表情包?ENS逆势上涨的新推力
多线程 里面 使用AtomicInteger类,保证线程安全
Selenium of reptiles
15、学习MySQL NULL 值处理
2022/08/02------丑数
“vite”和“vite预览”有什么区别?
CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes), problem: (D) Magical Array
Oracle备份的几种方式
多商户商城系统功能拆解21讲-平台端分销订单
有人知道flink sql 使用tableEnv.executeSql执行后,怎么获取到任务运行的
cocos creater 3.x 插件安装方法
数字IC笔迹-MCMM、WNS和TNS