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 #! ...
随机推荐
- java基础中this,super
this是自身的一个对象,代表对象本身,可以理解为:指向对象本身的一个指针. super可以理解为是指向自己超(父)类对象的一个指针,而这个超类指的是离自己最近的一个父类. this的用法就不累赘的说 ...
- asp.net core webapi/website+Azure DevOps+GitHub+Docker
asp.net core webapi/website+Azure DevOps+GitHub+Docker 新春开篇作,主要写一下关于asp.net core web/api 2.2 项目借助dev ...
- Kasaraju算法--强连通图遍历及其python实现
在理解有向图和强连通分量前必须理解与其对应的两个概念,连通图(无向图)和连通分量. 连通图的定义是:如果一个图中的任何一个节点可以到达其他节点,那么它就是连通的. 例如以下图形: 这是最简单的一个连通 ...
- AFNetworking源码浅析
本文将从最简单的GET请求方法的使用入手,由表及里,逐步探究AFNetworking如何封装处理原生的网络请求. 一.AFNetworking的简单使用 -(void)getDemo{ AFHTTPS ...
- 列表、enumerate()函数,以及查看数据类型所有的内置方法
随便看看 """ forList(): 测试list和enumerate()函数 examineFun(): 查看数据类型所有的内置方法 ""&quo ...
- navicat 将自增长字段重置(重新从1开始)的方法
先说明,此语句会将你的表中数据全部删除. 很简单,运行如下sql语句: TRUNCATE TABLE 表名;
- 本机不安装Oracle客户端,使用PL/SQL Developer和 Instant Client 工具包连接oracle 11g远程数据库
一.先到Oracle网站下载Instant Client 下载地址:http://www.oracle.com/technetwork/cn/database/features/instant-cli ...
- 【Python 09】汇率兑换2.0-2(分支语句)
分支语句:根据判断条件选择程序执行路径 1.使用方法 if <条件1>: <语句块1> elif <条件2>: <语句块2> ... else: < ...
- velocity模板引擎 -- java.io.FileNotFoundException: velocity.log (Permission denied)
问题原因是velocity的日志框架导致(velocity是使用自己封装的日志框架记录日志的),velocity在初始化Logger时,如果没有读取到配置文件,则会使用默认的velocity.log做 ...
- android开发学习 ------- 关于getSupportFragmentManager()不可用的问题
在Android开发中,少不了Fragment的运用. 目前在实际运用中,有v-4包下支持的Fragment以及app包下的Fragment,这两个包下的FragmentManager获取方式有点区别 ...