当前位置:网站首页>Shell script implements application service log warehousing MySQL
Shell script implements application service log warehousing MySQL
2022-07-04 22:22:00 【Wu_ Candy】
Today I'd like to share a shell Scripting tools , adopt shell Script vs mysql The combination of , Store the error output log of a specific service into the specified mysql In the table , So as to facilitate the positioning and analysis of error problems .
On a daily basis , Often need and linux The system deals with , for example : Service deployment 、 Log and service status viewing , and shell Scripts are and linux A common method of interaction . The following code example is in shell Embedded in the script mysql The configuration information drops the error log information into the database .
shell The script is as follows :
#!/usr/bin/env bash
hostName="l-beta.io"
dbPort=3306
dbUser="beta"
dbPassword="123456"
dbName="test_log"
tableName="beta_error_log_record"
env="test1"
base="/home/q/www"
# Into the dead cycle
while [[ 1 ]]; do
# Loop de ergodic base Folder under directory ,-vE The last two are the items to be excluded
for name in `ls $base | grep -vE "default|genesis"`;
do
#echo $base/$name
# Determine if it's a directory
if [[ -d $base/$name ]]; then
# Define the previous minute of the current time , It is used to filter and match the log content
before=`date -d "-1 minute" "+%Y-%m-%d %H:%M:"`
# echo "Watching log $name in $before"
# Filter and obtain catalina.out Last minute in the file Exception and Error journal
result=`grep -C5 "$before" $base/$name/logs/catalina.out | grep -vE "DEBUG|skywalking|10.8.0.37:8800" | grep -C5 -E "Exception|ERROR" | sed $'s/\'/\"/g' `
# If result If it is zero, skip this cycle
if [[ -z "$result" ]]; then
continue;
fi
echo "-------------------------->"
# Splicing insert sql sentence
insert_sql="insert into $tableName (environment,project_name,content) values('$env','$name','\n\nException:\n\n$result')"
echo $insert_sql > tmp.sql
echo "***********start*************"
echo $insert_sql
# Start execution sql sentence
mysql -h$hostName -P$dbPort -u$dbUser -p$dbPassword $dbName -e "source tmp.sql"
echo "************end************"
fi
done
# Input sleep 60s
echo -e "sleep 60 seconds\n"
sleep 60s
done
above shell The key information in the script is marked with corresponding comments , If you need to practice , Can be mysql The corresponding configuration information and the monitored log service path can be changed and replaced with the target information .
end
边栏推荐
- 嵌入式开发:技巧和窍门——提高嵌入式软件代码质量的7个技巧
- Why do you have to be familiar with industry and enterprise business when doing Bi development?
- 赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
- Éducation à la transmission du savoir | Comment passer à un test logiciel pour l'un des postes les mieux rémunérés sur Internet? (joindre la Feuille de route pour l'apprentissage des tests logiciels)
- i.MX6ULL驱动开发 | 24 - 基于platform平台驱动模型点亮LED
- Relational database
- QT - double buffer plot
- Machine learning notes mutual information
- odps 中 对表进行了一次备份,为什么在元数据库查m_table 时,两张表的逻辑大小不一致,但数
- HBuilder X 常用的快捷键
猜你喜欢
Scala下载和配置
卷积神经网络模型之——LeNet网络结构与代码实现
Tiktok actual combat ~ the number of comments is updated synchronously
LOGO特训营 第一节 鉴别Logo与Logo设计思路
湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章
【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
Nat. Commun.| 机器学习对可突变的治疗性抗体的亲和力和特异性进行共同优化
El tree combined with El table, tree adding and modifying operations
并发网络模块化 读书笔记转
Enabling digital economy Fuxin software attends the BRICs high level Forum on Sustainable Development
随机推荐
抖音实战~评论数量同步更新
Nat. Commun.| 机器学习对可突变的治疗性抗体的亲和力和特异性进行共同优化
Tiktok actual combat ~ the number of comments is updated synchronously
Embedded development: skills and tricks -- seven skills to improve the quality of embedded software code
《命令行上的数据科学第二版》校对活动重新启动
Concurrent optimization summary
Flask 上下文详解
The proofreading activity of data science on the command line second edition was restarted
服装企业为什么要谈信息化?
凭借了这份 pdf,最终拿到了阿里,字节,百度等八家大厂 offer
制作条形码的手机App推荐
DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效
虚拟人产业面临的挑战
Challenges faced by virtual human industry
赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
置信区间的画法
vim 从嫌弃到依赖(23)——最后的闲扯
1807. 替换字符串中的括号内容
面试题 01.08. 零矩阵
智洋创新与华为签署合作协议,共同推进昇腾AI产业持续发展