邮件监控云上脚本执行进度

25 篇文章 0 订阅

#!/bin/sh
#监控云上pay-data-load脚本执行进度 老脚本使用 已废弃
current_path=$(cd "$(dirname $0)"; pwd)
data_path="$current_path/time/"
file_input=$current_path/file_input

html_file=$current_path/pay_data_load.html
if [ -f "$html_file" ];then
    rm $html_file
fi

#if [ -f "$file_input" ];then
    #rm $file_input
#fi

function get_all_time_data(){
    #创建源数据文件
    touch $file_input
    echo "file_name input_time" > $file_input
    echo "file " `cat $data_path/data.time` >> $file_input
    echo "pre_file " `cat $data_path/pre-data.time` >> $file_input
    #判断pre_file日期是否为今天
    today=`date +'%Y%m%d'`
    pre_data_time=`cat $data_path/pre-data.time`
    if [[ "$today" != "$pre_data_time" ]]; then
        echo "FATAL: pre-data-file time is $pre_data_time,today data($today) is not load" >> "$current_path/log/pay-data-load.log.wf"
    fi
}

td_str=''
function htmlTpl(){
    DATE=`date +%Y-%m-%d`
    SUBJECT="云上数据导入进度 "$DATE
    HTML=`cat <<EOF
    From: mailbot_yun <mailbot_yun@xxx.com>
    To: daiyuanpei@xxx.com
    Subject: $SUBJECT
    Content-Type: text/html
    EOF`
    echo "$HTML" > $html_file
    echo -e "<html>
    <head>
    <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>" >> $html_file
}
function create_style(){
    style="<style type='text/css'>
        *{
             font-family: Helvetica, Arial, sans-serif;
             font-size: 12px;
         }
         table {
             border-collapse: collapse;
         }
         th, td {
             border: 1px solid black;
             padding: 10px;
         }
         th {
             text-align: center;
         }
         tr:nth-child(2) {
             background-color: #E4DFEC
         }
         tr td {
             width: 120px;
             padding: 8;
         }
     </style>
     </head>"
     echo -e $style >> $html_file
}

function create_table_head(){
    echo -e "<table border='1px solid black' cellspacing='0'>\n" >> $html_file
}

function create_html_end(){
    echo -e "</body>\n</html>" >> $html_file
}
#创建tr
function create_tr(){
    create_row_value "$1"
    echo -e "<tr>$td_str</tr>" >> $html_file
}

function create_row_value(){
    td_str=`echo  $1 \
    | awk  -F ' '   '
      {
         now=strftime("%Y%m%d")
         day=strftime("%Y%m%d",systime()-3600*24*7)

         input_content=$2
         if ($2~/[0-9]/ && $3~/[0-9]/){

             if ($2<=day){
                 input_content=$2"(至今超过一周未更新,请关注)"
             }
         }

         print "<td>"$1"</td>","<td>"input_content"</td>"

      }'`
}

#创建每一个td
function create_td(){
    td_str=`echo $1 | awk 'BEGIN{FS=" "}''{i=1; while(i<=NF) {print "<td>"$i"</td>";i++}}'`
}

#创建table标题
function create_table_title(){
    echo -e "<tr><th colspan='2'>数据导入进度</th></tr>" >> $html_file
}
#创建邮件html正文
function create_html(){
    htmlTpl
    create_style
    create_table_head
    create_table_title
    while read line;do
        create_tr "$line"
    done < $file_input
    create_html_end
}

function send_mail(){
    cat $html_file | /usr/sbin/sendmail -t
}
#入口
function main(){
    get_all_time_data
    create_html
    send_mail
}
main

if [ -f "$html_file" ];then
    rm $html_file
fi

if [ -f "$file_input" ];then
    rm $file_input
fi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值