Linux shell脚本 将数据库超时的订单号 发送给客服

来源:互联网 发布:怕死 陈奕迅 知乎 编辑:程序博客网 时间:2024/06/06 05:03
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.txtnum=$(cat overtimeorder.txt |wc -l)if [ $num -gt 1 ]then#echo "这是超时的订单号,请及时处理!" >> overtimeorder.txtmail -s "这是鉴宝超时的订单号,请及时处理!" 429756472@qq.com < overtimeorder.txtelse    echo "what?"fi2、发送实时订单号 #!/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.txtcomm -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.txtecho "send email"else    echo "Database has no relevant data! at ${TIMESTAMP}." >>${LOG}fi
0 0
原创粉丝点击