当前位置:网站首页>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
边栏推荐
- 短视频系统源码,点击屏幕空白处键盘不自动收起
- HDU - 1078 fatmouse and cheese (memory search DP)
- 面试必备 LeetCode 链表算法题汇总,全程干货!
- 嵌入式开发:技巧和窍门——提高嵌入式软件代码质量的7个技巧
- 微服务--开篇
- 面试题 01.01. 判定字符是否唯一
- With this PDF, we finally got offers from eight major manufacturers, including Alibaba, bytek and Baidu
- HBuilder X 常用的快捷键
- 湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章
- Solana链上应用Crema因黑客攻击停运
猜你喜欢

Enabling digital economy Fuxin software attends the BRICs high level Forum on Sustainable Development

智洋创新与华为签署合作协议,共同推进昇腾AI产业持续发展

迷失在Mysql的锁世界

VS2019 C# release下断点调试

玩转gRPC—深入概念与原理

Machine learning notes mutual information

Deveco device tool 3.0 release brings five capability upgrades to make intelligent device development more efficient

Tiktok actual combat ~ the number of comments is updated synchronously

UML图记忆技巧

Embedded development: skills and tricks -- seven skills to improve the quality of embedded software code
随机推荐
# 2156. Find the substring of the given hash value - post order traversal
【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
使用 BlocConsumer 同时构建响应式组件和监听状态
Concurrent network modular reading notes transfer
Force buckle 2_ 1480. Dynamic sum of one-dimensional array
【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
Basic structure of PostgreSQL - table
力扣98:验证二叉搜索树
阿里推出新品牌“瓴羊”,致力成为“数字化领头羊”
Scala下载和配置
What is business intelligence (BI), just look at this article is enough
Redis sentinel simply looks at the trade-offs between distributed high availability and consistency
短视频系统源码,点击屏幕空白处键盘不自动收起
时空预测3-graph transformer
置信区间的画法
Apachecn translation, proofreading, note sorting activity progress announcement 2022.7
Relational database
283. 移动零-c与语言辅助数组法
Common open source codeless testing tools
面试题 01.08. 零矩阵