当前位置:网站首页>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
边栏推荐
- Big guy, who is free to help me to see what the problem is, I just read MySQL source print, and I just came into contact with flink.
- H.265网页播放器EasyPlayer获取视频流正常,但是播放出现黑屏是什么原因?
- VsCode preview Geojson data
- Discuz新闻资讯GBK模板
- Oracle备份的几种方式
- Install porterLB
- 多肽介导PEG磷脂——靶向功能材料之DSPE-PEG-RGD/TAT/NGR/APRPG
- 全尺度表示的上下文非局部对齐,南科大&优图提出NAFS解决基于文本的Re ID
- cocos creater 3.x 插件安装方法
- 微信小程序分享功能
猜你喜欢
随机推荐
5000元价位高性能轻薄本标杆 华硕无双高颜能打
flink-sql 客户端,咋回事 我show tables 报错
cell delay和net delay
爬虫之selenium
mysql之的执行计划
微信小程序分享功能
【白话模电2】二极管特性和分类
二叉树求和路径问题解答与注记
es6新增-Promise详解(异步编程的解决方案1)
Uniswap或将开启“费用开关”,UNI持有者可享受分红
使用range-based for循环的注意事项
Oracle备份的几种方式
深度学习常用公式与命令总结(更新中)
域名抢注“卷”到了表情包?ENS逆势上涨的新推力
OSError: [WinError 123] 文件名、目录名或卷标语法不正确
“vite”和“vite预览”有什么区别?
5v2.1a给5v2a充电行吗
es6新增-async函数(异步编程的最终解决方案)
Arduino实验三:继电器实验
LeetCode - 102. 二叉树的层序遍历;110. 平衡二叉树;098. 验证二叉搜索树









