当前位置:网站首页>Mail monitoring cloud script execution progress

Mail monitoring cloud script execution progress

2022-06-25 19:09:00 Daiyuanpei

#!/bin/sh
# Monitoring cloud pay-data-load Script execution progress   Old scripts use   obsolete 
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(){
    # Create source data file 
    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
    # Judge pre_file Whether the date is today 
    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=" Cloud data import progress  "$DATE
    HTML=`cat <<EOF
    From: mailbot_yun <[email protected]>
    To: [email protected]
    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
}
# establish 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"( It has not been updated for more than a week , Please pay attention to )"
             }
         }

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

      }'`
}

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

# establish table title 
function create_table_title(){
    echo -e "<tr><th colspan='2'> Data import progress </th></tr>" >> $html_file
}
# Create mail html Text 
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
}
# entrance 
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

原网站

版权声明
本文为[Daiyuanpei]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190523357798.html