shell实战之日志脱敏-2.0
cfg
# This is generated to be a configuration file.
# kay
# // # This is a parameter for crontab and objective file.
interval=
begin=
end= # There are some log path
# logpath=/root/shell/log/;/root/shell/log/;/root/shell/log/
logpath=/home/pospadm/trc # sh path
shpath=/home/pospadm/log-shell/log-secret/start.sh # keylab path
keylabpath=/home/pospadm/log-shell/log-secret/key
collect.sh
#!/bin/bash - # Used to collect value list
# kay
# Version: 1.0
# // # key list
keylist=`cat ${keylabpath}` # golobal value list
valuelist=""
index= # collect value by key in directory
# @Parameter: directory file
collect_list()
{
for key in ${keylist}
do
if grep -qr ${key} $
then
f0="/<"$key">/p"
f1="<"$key">"
f2="s/<"$key">/\n"$key"=/gp"
f3="s/<\/"$key">/\n/gp"
f4="/"$key"=/p"
f5="s/"$key"=//gp"
#f6="\$!N;/^\(.*\)\n\key$/!P;D"
#f6=":key;N;s/^(\S+)((\n.*)*)\n\key$/\key\2/M;\$!bkey" #list=`sed -n ${f0} $ | sed -n ${f2} | sed -n ${f3} | sed -n ${f4} | sed -n ${f5}`
#list=`grep ${f1} $ | sed -n ${f2} | sed -n ${f3} | sed -n ${f4} | sed -n ${f5}`
list=`grep -r ${f1} $ | sed -n ${f2} | sed -n ${f3} | sed -n ${f4} | sed -n ${f5}`
#list=`grep -r ${f1} $ | sed -n ${f2} | sed -n ${f3} | sed -n ${f4} | sed -n ${f5} | sort -k2n | sed ${f6}`
#list=`grep -r ${f1} $ | sed -n ${f2} | sed -n ${f3} | sed -n ${f4} | sed -n ${f5} | sed -r ${f6}` for l in ${list}
do
valuelist[index]=${l}
((index++))
done
fi
done
}
crontab.sh
#!/bin/bash - # Used to do a crontab task
# kay
# Version: 1.0
# // # @Name: docrontab
# @Parameter: specific crontab task
docrontab()
{
cronfile="/tmp/crontab.${USER}"
crontab -l > ${cronfile}
query=`echo "$1" | sed 's/*/\\\*/g'`
grep -q "${query}" ${cronfile} && echo "" ||
{
echo "$1" >> ${cronfile}
crontab ${cronfile}
}
rm -f ${cronfile}
}
key
track_2
track_3
pan
exp_dt
ic_dat
pin_key
track_key
trm_key
tpklmk
zaklmk
zpklmk
pin_data
readme
本脚本使用方法说明:
.配置环境变量
# vi ~/.bash_profile
export desen_path=/root/shell2
#source ~/.bash_profile
.配置文件说明
文件cfg
interval为定时任务间隔时间
begin为查找的文件范围起始时间点
end为查找的文件范围的戒指时间点
logpath为要处理的日志路径,多个路径用;隔开
shpath为本脚本所在绝对路径
keylabpath为关键字字典文件所在绝对路径
.关键字字典文件
里面的每一个关键字应该是日志内<></>内的内容
要替换的内容为标签内的内容
.启动脚本
./start.sh
调试方法:
#nohup bash -x start.sh >tt.log &
.停止脚本
#./stop.sh
start.sh
#!/bin/bash - # This file is used to handle log desensitization
# kay
# Version: 1.0
# // . ${HOME}/.bash_profile
. ${desen_path}/util.sh
. ${desen_path}/crontab.sh
. ${desen_path}/collect.sh # write log
logfile="log.txt"
echo "["`date`"] start script." >> ${logfile} # add crontab
task="*/"${interval}" * * * * "${shpath}
docrontab "${task}" dir1=""
dir2=""
# read config file and handle every file and directiory
for d in ${logpath}
do
tmp="/tmp/find.ret"
# search for all changed file between time begin and end
ret=`find "${d}" -mmin +"${begin}" -mmin -"${end}" -type f`
if [ "${ret}" != "" ]
then
echo ${ret} | xargs ls -rt > ${tmp}
file1=`sed -n '1p' ${tmp}`
file2=`sed -n '$p' ${tmp}`
rm -f ${tmp}
dir1=`echo ${file1} | sed -r 's/^(\/.*\/)[^/]+\/?/\1/g'`
dir2=`echo ${file2} | sed -r 's/^(\/.*\/)[^/]+\/?/\1/g'`
collect_list ${dir1}
if [ "${dir1}" != "${dir2}" ]
then
collect_list ${dir2}
fi
fi done # filter the global list. delete the same value.
# "echo ${globallist[@]} | sort -k2n | sed ":;N;s/^(\S+)((\n.*)*)\n\$/\\/M;\$!b1"
valuelist=($(awk -vRS=' ' '!a[$1]++' <<< ${valuelist[@]})) # hanlde a directory
handle_directory()
{
for l in ${valuelist[@]}
do
cnb=""
len=${#l}
if [ ${len} -gt ]
then
cnb="5-"$((${len} - ))
else
cnb="1-"${len}
fi
mid=`echo ${l} | cut -nb ${cnb} | sed 's/*/\\\*/g'`
h=`echo ${l} | sed 's/'${mid}'/*******/g'`
f=`echo "${l}" | sed 's/*/\\\*/g'` #sed -i 's/'${f}'/'${h}'/g' ${c}
grep -rl "${f}" $ | xargs sed -i 's/'${f}'/'${h}'/g'
done
} if [ "${dir1}" != "" ]
then
handle_directory ${dir1}
if [ "${dir1}" != "${dir2}" ]
then
handle_directory ${dir2}
fi
fi echo "["`date`"] end script." >> ${logfile} exit
stop.sh
#!/bin/bash - # Used to stop script and crontab
# kay
# Version: 1.0
# // crontab -r
ps -ef | grep 'start' | awk -F ' ' '{ print $2 }' | xargs kill -
util.sh
#!/bin/bash - # Read config
# kay
# Version: 1.0
# // # configuration file path
config=${desen_path}/"cfg" # config parameters
prefix=`grep -v "^#" ${config}`
interval=`echo "${prefix}" | grep "interval" | awk -F "=" '{ print $2 } '`
begin=`echo "${prefix}" | grep 'begin' | awk -F '=' '{ print $2 } '`
end=`echo "${prefix}" | grep 'end' | awk -F '=' '{ print $2 } '`
logpath=`echo "${prefix}" | grep 'logpath' | awk -F '=' '{ print $2 }' | awk -F ';' '{ for(i=1;i<=NF;i++) print $i }'`
shpath=`echo "${prefix}" | grep 'shpath' | awk -F '=' '{ print $2 }'`
keylabpath=`echo "${prefix}" | grep 'keylabpath' | awk -F '=' '{ print $2 }'`
shell实战之日志脱敏-2.0的更多相关文章
- shell实战之日志脱敏
本次实战目标为日志脱敏,将日志目录内的所有文件进行处理,凡是涉及到卡号和密码的信息,一律以“*”号替代,要替代的内容都从对应的标签内获取,本脚本执行目录 drwxr-xr-x 5 root root ...
- shell实战之日志备份
util.sh #!/bin/bash - # Read config # kay # Version: 1.0 # // # configuration file path config=${log ...
- java 日志脱敏框架 sensitive-v0.0.4 系统内置常见注解,支持自定义注解
项目介绍 日志脱敏是常见的安全需求.普通的基于工具类方法的方式,对代码的入侵性太强.编写起来又特别麻烦. 本项目提供基于注解的方式,并且内置了常见的脱敏方式,便于开发. 特性 基于注解的日志脱敏. 可 ...
- java 日志脱敏框架 sensitive-新版本0.0.2-深度拷贝,属性为对象和集合的支持
项目介绍 日志脱敏是常见的安全需求.普通的基于工具类方法的方式,对代码的入侵性太强.编写起来又特别麻烦. 本项目提供基于注解的方式,并且内置了常见的脱敏方式,便于开发. 用户也可以基于自己的实际需要, ...
- Java日志脱敏框架 sensitive-v0.0.4 系统内置常见注解,支持自定义注解
项目介绍 日志脱敏是常见的安全需求.普通的基于工具类方法的方式,对代码的入侵性太强.编写起来又特别麻烦. 本项目提供基于注解的方式,并且内置了常见的脱敏方式,便于开发. 特性 基于注解的日志脱敏. 可 ...
- 用shell统计访问日志里每个ip访问次数【转】
今天,要统计一个系统的每个ip访问次数,于是我找到该系统访问日志,并写脚本实现. 访问日志情况: [root@qular ~]# cd /usr/local/nginx/logs/ [root@q ...
- log4j 日志脱敏处理 + java properties文件加载
Java 加载Properties 配置文件: ResourceBundle bundle = ResourceBundle.getBundle("log4j_filter"); ...
- java 日志脱敏框架 sensitive,优雅的打印脱敏日志
问题 为了保证用户的信息安全,敏感信息需要脱敏. 项目开发过程中,每次处理敏感信息的日志问题感觉很麻烦,大部分都是用工具类单独处理,不利于以后统一管理,很不优雅. 于是,就写了一个基于 java 注解 ...
- Shell + crontab 实现日志压缩归档
Shell + crontab 实现日志压缩归档 crontab # archive the ats log days. */ * * * * root /bin/>& shell #! ...
随机推荐
- 调用android的getColor()方法出现 java.lang.NoSuchMethodError: android.content.res.Resources.getColor
1.java.lang.NoSuchMethodError: android.content.res.Resources.getDrawable/getColor或者 java.lang.NoSuch ...
- 南京邮电大学java第三次实验报告
实 验 报 告 ( 2017 / 2018学年 第2学期) 课程名称 JAVA语言程序设计 实验名称 Java集成开发环境的安装与使用. Java变量.表达式与控制结构 实验时间 2018 年 4 月 ...
- myapp——自动生成小学四则运算题目的命令行程序(侯国鑫 谢嘉帆)
1.Github项目地址 https://github.com/baiyexing/myapp.git 2.功能要求 题目:实现一个自动生成小学四则运算题目的命令行程序 功能(已全部实现) 使用 -n ...
- MongoDB 常用的数据备份梳理汇总
1.基于数据文件的备份 直接将原始的数据文件Copy至备份的地方,这个方法的优点是比较快,因为备份和恢复都不需要转换数据格式.缺点就是需要锁住数据库服务器,但是此方案通常备份是在从节点上进行,备份过程 ...
- org.springframework.beans.factory.NoUniqueBeanDefinitionException 导致原因之一
导致此异常原因很多,以下仅是针对其中一种因素的解决办法. 下面是DAO接口.Service接口.Service实现类的全路径名(全部定义在com.xxx.projetc包下) com.xxx.proj ...
- Python高级应用(3)—— 为你的项目添加验证码
验证码简介 验证码的作用: 验证码在现在来说,是很常见的东西,可以一定程度的保护网站,比如防止网络爬虫恶意爬取网站数据啊,减少低级的攻击啊什么的.但是高级点的骚操作还是不太好防范,所以现在的验证码平台 ...
- System.map文件的作用
有关System.map文件的信息好象很缺乏.其实它一点也不神秘,并且在整个事情当中它并不象看上去那么得重要.但是由于缺乏必要的文档说明,使其显得比较神秘.它就象耳垂,我们每个人都有,但却不知道是干什 ...
- 深入Ambari Metrics 机制分析
0.简介 Ambari作为一款针对大数据平台的运维管理工具,提供了集群的创建,管理,监控,升级等多项功能,目前在业界已经得到广泛使用. Ambari指标系统( Ambari Metrics Syste ...
- Linux安装python2.7
一.Python安装 以Python-2.7.7为例,安装包:Python-2.7.7.tgz如无特殊说明,以下安装步骤都采用root用户执行 1. 解压Python-2.7.7.tgz tar -x ...
- SpringBoot使用JSP(官网Demo)
最开始接触java的时候,前端页面基本都是用jsp来写,最近公司项目要使用SpringBoot重构,查看SpringBoot文档,发现SpringBoot不建议使用JSP,因为jsp在使用内嵌serv ...