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 #! ...
随机推荐
- Paint.FontMetrics
要了解TextView对文本的绘制,那么就需要了解Paint.FontMetircs. 官方对该类的解释是:Class that describes the various metrics for a ...
- 测者的测试技术手册:自动的自动化框架EvoSuite集成Cobertura得到可视化的代码覆盖报告
EvoSuite是由Sheffield等大学联合开发的一种开源工具,用于自动生成测试用例集,生成的测试用例均符合Junit的标准,可直接在Junit中运行.得到了Google和Yourkit的支持. ...
- PYTHON常用数据类型(列表,元组,字典)
一.数字 1.整形:就是整数. 2.浮点型:就是小数. 3.布尔型:True或者是False,python里严格区分格式,空格缩进或者是大小写. 4.运算符有+ – * / ()%(求模运算取余数)* ...
- SQL 日期时间比较
原先的判断是 ae.首次受理时刻 >= '2015/12/1 0:00:00' AND ae.首次受理时刻 <= '2015/12/25 0:00:00' ,改为如下和时间变量比较 效率 ...
- c/c++ 多线程 unique_lock的使用
多线程 unique_lock的使用 unique_lock的特点: 1,灵活.可以在创建unique_lock的实例时,不锁,然后手动调用lock_a.lock()函数,或者std::lock(lo ...
- A Deep Learning-Based System for Vulnerability Detection(二)
接着上一篇,这篇研究实验和结果. A.用于评估漏洞检测系统的指标 TP:为正确检测到漏洞的样本数量 FP:为检测到虚假漏洞样本的数量(误报) FN:为未检真实漏洞的样本数量(漏报) TN:未检测到漏洞 ...
- springclound
https://blog.csdn.net/w893932747/article/details/80896315 //这个有怎么创建client的 https://blog.csdn.net/m0_ ...
- 26 python 初学(线程、同步锁、死锁和递归锁)
参考博客: www.cnblogs.com/yuanchenqi/articles/5733873.html 并发:一段时间内做一些事情 并行:同时做多件事情 线程是操作系统能够进行运算调度的基本单位 ...
- (十三)Batch Processing
In addition to being able to index, update, and delete individual documents, Elasticsearch also prov ...
- [properJavaRDP]在网页中实现远程连接
内容摘要: 利用开源软件properJavaRDP实现远程桌面连接 如何让Applet嵌入到网页中正常运行 如何处理连接win7时的异常:Wrong modulus size! Expected 64 ...