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 #! ...
随机推荐
- nginx配置静态项目
当nignx可以加载下面的这个service时 server { listen 8085; server_name 1.192.60.82; location / { root /etc/nginx ...
- 01-vue学习之前的准备
一.具备的基础知识 1.扎实的HTML/CSS/Javascript基本功,这是前置条件. 2.不要用任何的构建项目工具,只用最简单的<script>,把教程里的例子模仿一遍,理解用法.不 ...
- PJSUA2开发文档--第十二章 PJSUA2 API 参考手册
12 PJSUA2 API 参考手册 12.1 endpoint.hpp PJSUA2基本代理操作. namespace pj PJSUA2 API在pj命名空间内. 12.1.1 class En ...
- Network Policy - 每天5分钟玩转 Docker 容器技术(171)
Network Policy 是 Kubernetes 的一种资源.Network Policy 通过 Label 选择 Pod,并指定其他 Pod 或外界如何与这些 Pod 通信. 默认情况下,所有 ...
- 启动期间的内存管理之bootmem_init初始化内存管理–Linux内存管理(十二)
1. 启动过程中的内存初始化 首先我们来看看start_kernel是如何初始化系统的, start_kerne定义在init/main.c?v=4.7, line 479 其代码很复杂, 我们只截取 ...
- Python爬虫之正则表达式(3)
# re.sub # 替换字符串中每一个匹配的子串后返回替换后的字符串 import re content = 'Extra strings Hello 1234567 World_This is a ...
- OKR源自德鲁克和格鲁夫,跟谷歌是天作之合:4星|《这就是OKR》
这就是OKR,[美]约翰杜尔(John Doerr),中信出版社,9787508696881 作者以实习生的身份加入英特尔,跟格鲁夫有交集,见证了格鲁夫在英特尔创立OKR的过程和英特尔使用OKR作为管 ...
- 面向对象___str__和__repr__
老师的博客关于此知识点 http://www.cnblogs.com/Eva-J/articles/7351812.html#_label7 __str__和__repr__ 改变对象的字符串显示__ ...
- linux 配置vim(vimrc)
打开终端:ctrl+alt+t 进入vim文件:cd /etc/vim 打开vimrc文件:sudo gedit vimrc 然后在行末if语句前加上下面的内容," 这个符号为注释,后面内 ...
- Git命令行管理代码、安装及使用
出处:https://www.cnblogs.com/ximiaomiao/p/7140456.html Git安装和使用 目的:通过Git管理github托管项目代码 一.下载安装Git 1 ...