1、SHELL 脚本 将超时的数据库订单号(所有的) 发送给客服 实例:
#!/bin/bash
# Define log
USERNAME="root"
PASSWORD="xx"
DBNAME="tgq_master" #数据库名称
TABLENAME="appraisal_apply" #数据库中表的名称
#查询
select_sql="SELECT order_sn as '订单号' from ${TABLENAME} a where a.status = 1 AND a.apply_time < unix_timestamp(now())-(select value from config where name='appraisal_time_limit')*60"
mysql -u${USERNAME} -p${PASSWORD} ${DBNAME} -e "${select_sql}" > overtimeorder.txt
num=$(cat overtimeorder.txt |wc -l)
if [ $num -gt 1 ]
then
#echo "这是超时的订单号,请及时处理!" >> overtimeorder.txt
mail -s "这是鉴宝超时的订单号,请及时处理!" 429756472@qq.com < overtimeorder.txt
else
echo "what?"
fi
2、发送实时订单号
#!/bin/bash
# Define log 默认订单超过xx分钟发给客服
#写入日志文件
TIMESTAMP=`date +%F_%H:%M:%S`
#LOG=call_sql_${TIMESTAMP}.log
LOG=call_sql_shell.log
echo "Send order_sn Start select sql statement at ${TIMESTAMP}." >>${LOG}
#数据库信息
USERNAME="root"
PASSWORD="xxxxx"
DBNAME="tgq_master" #数据库名称
TABLENAME="appraisal_apply" #数据库中表的名称
#查询
select_sql="SELECT order_sn as '订单号' from ${TABLENAME} a where a.status = 1 AND a.apply_time < unix_timestamp(now())-(select value from config where name='appraisal_time_limit')*60"
mysql -u${USERNAME} -p${PASSWORD} ${DBNAME} -e "${select_sql}" > overtimeorderall.txt
#比较两个文件的不同之处 并赋予新文件
#找出a.txt文件有而b.txt文件中没有的放在c.txt文件中
comm -23 overtimeorderall.txt overtimeorderold.txt > overtimeordernew.txt
comm -23 overtimeorderall.txt overtimeorderold.txt >> overtimeorderold.txt
#查询最新超时订单号文件 的行数
num=$(cat overtimeordernew.txt |wc -l)
#行数大于0 存在则发送邮件 不存在写入日志文件
if [ $num -gt 0 ]
then
#发送邮件
mail -s "这是鉴宝超时的订单号,请及时处理!" 429756472@qq.com < overtimeordernew.txt
echo "send email"
else
echo "Database has no relevant data! at ${TIMESTAMP}." >>${LOG}
fi
Linux shell脚本 将数据库超时的订单号 发送给客服
最新推荐文章于 2018-12-18 22:59:44 发布