一、背景
需要通过每天查询数据交易,进行业务情况监控,并出现指标时提醒关注
二、shell脚本
#!bin/bash
### 查询监控脚本
##钉钉token
DD_TOKEN="XXX"
# 数据库配置
DB_HOST="XXX"
DB_PORT="XXX"
DB_USER="XXX"
DB_PASS="XXX"
DB_NAME="XXX"
previous_day=$(date -d '1 day ago' +'%d')
DB_TABLE="XXXX_${previous_day}"
DB_SQL="select COUNT(1) AS 数量 from ${DB_TABLE} where XXX;"
## 连接数据库
MYSQL_ETL="mysql -h $DB_HOST -u $DB_USER -P $DB_PORT -p${DB_PASS} $DB_NAME -e"
echo $previous_day
echo $DB_TABLE
echo $DB_SQL
echo ${MYSQL_ETL}
count_result=$($MYSQL_ETL "${DB_SQL}")
echo $count_result
result_num=`echo ${count_result} | awk '{print $2}'`
echo ${result_num}
if [ ${result_num} -eq 0 ];then
content="手续费${DB_TABLE}监控统计提醒${count_result},无需关注"
else
content="手续费${DB_TABLE}监控统计提醒${count_result},请尽快核实"
fi
echo ${content}
curl "https://oapi.dingtalk.com/robot/send?access_token=${DD_TOKEN}" -H 'Content-Type:application/json' -d "{\"msgtype\":\"text\",\"text\":{\"content\":\"$content\"}}"
三、定时任务
## 定时任务列表查看
crontab -l
## 定时任务编辑
crontab -e