vsftpd.log日志翻译
vsftpd.log日志翻译
请将脚本完整复制到Linux中,并和日志文件放在同一目录下
如果您需要先复制到windows中然后上传上去请在终端运行
dos2unix xxx.sh
chmod +x xxx.sh
整体脚本如下:
#!/bin/bash
# 提示用户输入日志文件名
echo -n "请输入需要翻译的日志文件名: "
read input_file
# 检查文件是否存在
if [[ ! -f "$input_file" ]]; then
echo "日志文件 $input_file 不存在,请检查文件名后重试!"
exit 1
fi
# 翻译并排版日志内容
echo "正在翻译并排版日志文件:$input_file"
perl -pe 's/\\x([0-9A-Fa-f]{2})/chr(hex($1))/eg' "$input_file" | while read -r line; do
if echo "$line" | grep -qE 'OK|FAIL'; then
echo "$line" | awk '
match($0, /^([A-Za-z]{3}\s+[A-Za-z]{3}\s+[0-9]{1,2}\s+[0-9:]{8}\s+[0-9]{4})\s+\[pid\s+([0-9]+)\]\s+\[([^\]]+)\]\s+(OK|FAIL)\s+(UPLOAD|DOWNLOAD):\s+Client\s+"([^"]+)",\s+"([^"]+)",\s+([0-9]+)\s+bytes,\s+([0-9.]+)Kbyte\/sec$/, groups) {
print "日期时间 : " groups[1]
print "进程ID : " groups[2]
print "用户 : " groups[3]
print "操作状态 : " groups[4]
print "操作类型 : " groups[5]
print "客户端地址 : " groups[6]
print "文件路径 : " groups[7]
print "文件大小 : " groups[8] " 字节"
print "传输速度 : " groups[9] " KB/秒"
print "--------------------------------------------"
}'
elif echo "$line" | grep -qE '^\w+\s+\w+\s+[0-9]+\s+[0-9:]+\s+[0-9]{4}'; then
echo "$line" | awk '
match($0, /^([A-Za-z]{3}\s+[A-Za-z]{3}\s+[0-9]{1,2}\s+[0-9:]{8}\s+[0-9]{4})\s+([0-9]+)\s+::ffff:([0-9.]+)\s+([0-9]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)$/, groups) {
print "日期时间 : " groups[1]
print "连接数 : " groups[2]
print "客户端IP : " groups[3]
print "文件大小 : " groups[4] " 字节"
print "文件路径 : " groups[5]
print "模式 : " groups[6]
print "方向 : " groups[7]
print "传输类型 : " groups[8]
print "用户名 : " groups[9]
print "协议 : " groups[10]
print "会话ID : " groups[11]
print "附加信息 : " groups[12]
print "--------------------------------------------"
}'
else
echo "未识别的日志格式: $line"
echo "--------------------------------------------"
fi
done
请确保您的vsftpd.log的输出日志没有进行人为修改,如:
Thu Dec 12 08:51:31 2024 [pid 2365327] [swdx] FAIL DOWNLOAD: Client "::ffff:10.201.3.179", "/\xE4\xBC\x9A\xE8\xAE\xAE\xE7\xBB\x84/\xE5\xBD\x95\xE5\x83\x8F\xE6\x95\x99\xE5\xAD\xA6\xE8\xA7\x86\xE9\xA2\x91/\xE4\xB9\xA0\xE8\xBF\x91\xE5\xB9\xB3\xE5\x85\xB3\xE4\xBA\x8E\xE7\xA4\xBE\xE4\xBC\x9A\xE4\xB8\xBB\xE4\xB9\x89\xE7\xA4\xBE\xE4\xBC\x9A\xE5\xBB\xBA\xE8\xAE\xBE\xE9\x87\x8D\xE8\xA6\x81\xE8\xAE\xBA.mp4", 651964 bytes, 15752.48Kbyte/sec
运行脚本后将输出:
[root@localhost vsftpd_log]# ./echo.sh
请输入需要翻译的日志文件名: vsftpd.log-20241213
正在翻译并排版日志文件:vsftpd.log-20241213
日期时间 : Thu Dec 12 08:51:31 2024
进程ID : 2365327
用户 : swdx
操作状态 : FAIL
操作类型 : DOWNLOAD
客户端地址 : ::ffff:10.201.3.179
文件路径 : /会议组/录像教学视频/***关于社会主义社会建设重要论.mp4
文件大小 : 651964 字节
传输速度 : 15752.48 KB/秒
--------------------------------------------
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)