#!/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
邮件监控云上脚本执行进度
最新推荐文章于 2022-11-14 12:02:01 发布