当前位置:网站首页>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
边栏推荐
- 如何实现轻松管理1500万员工?
- 机器人相关课程考核材料归档实施细则2022版本
- 【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
- UML图记忆技巧
- 力扣98:验证二叉搜索树
- VIM from dislike to dependence (23) -- the last gossip
- The drawing method of side-by-side diagram, multi row and multi column
- 保证接口数据安全的10种方案
- 并列图的画法,多排多列
- Which securities company has the lowest Commission for opening an account online? I want to open an account. Is it safe to open an account online
猜你喜欢
With this PDF, we finally got offers from eight major manufacturers, including Alibaba, bytek and Baidu
传智教育|如何转行互联网高薪岗位之一的软件测试?(附软件测试学习路线图)
Deveco device tool 3.0 release brings five capability upgrades to make intelligent device development more efficient
Scala download and configuration
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
el-tree结合el-table,树形添加修改操作
将QA引入软件开发生命周期是工程师要遵循的最佳实践
【C语言进阶篇】数组&&指针&&数组笔试题
赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
Xiangjiang Kunpeng joined the shengteng Wanli partnership program and continued to write a new chapter of cooperation with Huawei
随机推荐
sqlserver对数据进行加密、解密
Concurrent network modular reading notes transfer
Concurrent optimization summary
idea中pom.xml依赖无法导入
【C语言进阶篇】数组&&指针&&数组笔试题
复数在数论、几何中的用途 - 曹则贤
机器学习笔记 - 互信息Mutual Information
国产数据库乱象
Implementation rules for archiving assessment materials of robot related courses 2022 version
Force buckle 3_ 383. Ransom letter
Shell 脚本实现应用服务日志入库 Mysql
短视频系统源码,点击屏幕空白处键盘不自动收起
Kdd2022 | what features are effective for interaction?
Xiangjiang Kunpeng joined the shengteng Wanli partnership program and continued to write a new chapter of cooperation with Huawei
Jvm-Sandbox-Repeater的部署
vim 从嫌弃到依赖(23)——最后的闲扯
PHP short video source code, thumb animation will float when you like it
2022-07-04:以下go语言代码输出什么?A:true;B:false;C:编译错误。 package main import “fmt“ func main() { fmt.Pri
i.MX6ULL驱动开发 | 24 - 基于platform平台驱动模型点亮LED
Cadre WebGIS - kalrry