zoukankan      html  css  js  c++  java
  • 一个查询指定错误记录数据表错误记录条数的shell脚本

    #!/bin/bash
    #author:skycheng
    
    #parameters
    db_user=dbuser
    db_pass=dbpass
    db_host=xxx.xxx.xxx.xxx
    database=database
    
    #get current date string
    datestr=`date +'%Y-%m-%d'`
    start_time=`date +'%Y-%m-%d %H:%M:%S'`
    table_name='inf_log_err_'`date +'%Y%m%d'`
    
    #get logfile name
    logfile='/var/log/fs/get_err_record_'$datestr'.log'
    if [ ! -f $logfile ]
    then
    sudo touch $logfile
    sudo chmod 666 $logfile
    fi
    tmplogfile='/var/log/fs/get_err_record_tmp.log'
    if [ ! -f $tmplogfile ]
    then
    sudo touch $tmplogfile
    sudo chmod 666 $tmplogfile
    fi
    echo starttime:$start_time>>$logfile
    
    do_get_record()
    {
    query_sql="SELECT created,epid,sub_result,diffnum_sub,client_ip FROM "$table_name" WHERE created BETWEEN DATE_ADD(now() ,INTERVAL -10 MINUTE) AND DATE_ADD(now() ,INTERVAL 0 MINUTE) ORDER BY created DESC"
    mysql -u$db_user -h$db_host -p$db_pass $database -e "$query_sql"|sed 1d>$tmplogfile
    if [ $? -eq 0 ]
    then
    records_counts=`cat $tmplogfile|wc -l`
    if [ $records_counts -ge 10 ]
    then
    rdate=`sed -n '1'p $tmplogfile|awk -F " " '{print $1}'`
    rtime=`sed -n '1'p $tmplogfile|awk -F " " '{print $2}'`
    epid=`sed -n '1'p $tmplogfile|awk -F " " '{print $3}'`
    sub_result=`sed -n '1'p $tmplogfile|awk -F " " '{print $4}'`
    diffnum_sub=`sed -n '1'p $tmplogfile|awk -F " " '{print $5}'`
    client_ip=`sed -n '1'p $tmplogfile|awk -F " " '{print $6}'`
    echo $records_counts'|rdate='$rdate $rtime 'epid='$epid 'sub_result='$sub_result' diffnum_sub='$diffnu m_sub' client_ip='$client_ip
    else
    echo $records_counts
    fi
    else
    exit 1
    fi
    }
    do_get_record
  • 相关阅读:
    Bootstrap-table一个表格组件神器(学习二)实战
    JS基础_for循环练习3
    JS基础_for循环练习2
    JS基础_for循环练习1
    JS基础_for循环
    JS基础_while的练习2
    JS基础_while的练习1
    JS基础_while循环
    JS基础_条件分支语句:switch语句
    JS基础_if注意问题
  • 原文地址:https://www.cnblogs.com/sky-cheng/p/10565580.html
Copyright © 2011-2022 走看看