shell 拼接html table 发送邮件
#!/bin/bash kettleConfigHome=/home/vmuser/linbo/kettleDemo/job/config api_csv_path_home=/home/vmuser/linbo/test_upload/data_file prod_tableHead="<table border=\"1\"style=\"border-collapse:collapse;\"><tr><th>No</th><th>evn.prod</th><th>fileName</th><th>fileSize</th><th>fileRowCnt</th></tr>" test_tableHead="<table border=\"1\"style=\"border-collapse:collapse;\"><tr><th>No</th><th>evn.test</th><th>fileName</th><th>fileSize</th><th>fileRowCnt</th></tr>" evnArr=(prod test) declare -A prod_tableRowInfo declare -A test_tableRowInfo #dtformat=`date -d "4 day ago" +"%Y-%m-%d"` #lastday=`date -d "4 day ago" +"%Y-%m-%d"` dtformat=`date +"%Y-%m-%d"` index=0 k=0 apiNames=(`ls -rt $api_csv_path_home`) #t_burberry_sales_daily bz_return_order bz_return_order_line unilever_three_shop_sales_retrun ca_order_return unilever_sales_and_retrun mk_refund nike_gc_dgtl_hk_demand nike_odi_hk nike_odi_tmall nike_gc_dgtl_gp_order nike_hk_china_demand mk_bzsales disney_sales_return #apiNames=(t_burberry_sales_daily bz_return_order bz_return_order_line unilever_three_shop_sales_retrun ca_order_return unilever_sales_and_retrun mk_refund nike_gc_dgtl_hk_demand nike_odi_hk nike_odi_tmall nike_gc_dgtl_gp_order nike_hk_china_demand mk_bzsales disney_sales_return) for apiName in ${apiNames[*]} do for ((i=0;i<${#evnArr[*]};i++)); do cd $api_csv_path_home/$apiName/${evnArr[i]} cmmd0="ls --full-time ./ | sed -n '/${dtformat}/p' | awk '{print \$9}'" cmmd1="ls --full-time ./ | sed -n '/${dtformat}/p' | awk '{print \$5\"B\"}'" if [[ ${evnArr[i]} = prod ]]; then prod_fileArr=(`eval $cmmd0`) prod_fileSizeArr=(`eval $cmmd1`) prod_EvnAndDataArr[k]="${apiName}.${evnArr[i]}.[${#prod_fileArr[*]}]" #获取每个文件的行数 ; prod_fizeRowCntArr=() for (( a=0;a<${#prod_fileArr[*]};a++)); do rowCnt0=`cat ${prod_fileArr[$a]} | wc -l` prod_fizeRowCntArr[$a]="${rowCnt0}行" done # 将数据按一定的格式放入prod_tableRowInfo 中 if [[ ${#prod_fileArr[*]} -le 1 ]]; then # echo " ${#prod_fileArr[*]} -eq 1 " row="<tr><td>${index}</td><td>${prod_EvnAndDataArr[0]}</td><td>${prod_fileArr[0]}</td><td>${prod_fileSizeArr[0]}</td><td>${prod_fizeRowCntArr[0]}</td></tr>" elif [[ ${#prod_fileArr[*]} -gt 1 ]]; then # echo " ${#prod_fileArr[*]} -gt 1 " for ((b=0;b<${#prod_fileArr[*]};b++)); do if [ $b -eq 0 ]; then row="<tr><td rowspan=\"${#prod_fileArr[*]}\">${index}</td> <td rowspan=\"${#prod_fileArr[*]}\">${prod_EvnAndDataArr[$b]}</td><td>${prod_fileArr[$b]}</td><td>${prod_fileSizeArr[$b]}</td><td>${prod_fizeRowCntArr[$b]}</td></tr>" else row="${row}<tr> <td colspan=\"1\">${prod_fileArr[$b]}</td> <td>${prod_fileSizeArr[$b]}</td><td>${prod_fizeRowCntArr[$b]}</td></tr>" fi done fi prod_tableRowInfo["$index"]="$row" else test_fileArr=(`eval $cmmd0`) test_fileSizeArr=(`eval $cmmd1`) test_EvnAndDataArr[k]="${apiName}.${evnArr[i]}.[${#test_fileArr[*]}]" #获取每个文件的行数 ; test_fizeRowCntArr=() for (( a=0 ;a<${#test_fileArr[*]} ;a++ )); do rowCnt1=`cat ${test_fileArr[$a]} | wc -l` test_fizeRowCntArr[$a]="${rowCnt1}行" done # ------------------------------------------------------------------------------------------------------------------------------------------- if [[ ${#test_fileArr[*]} -le 1 ]]; then # echo " ${#test_fileArr[*]} -eq 1 " row="<tr><td>${index}</td><td>${test_EvnAndDataArr[0]}</td><td>${test_fileArr[0]}</td><td>${test_fileSizeArr[0]}</td><td>${test_fizeRowCntArr[0]}</td></tr>" elif [[ ${#test_fileArr[*]} -gt 1 ]]; then # echo " ${#test_fileArr[*]} -gt 1 " for ((b=0;b<${#test_fileArr[*]};b++)); do if [ $b -eq 0 ]; then row="<tr><td rowspan=\"${#test_fileArr[*]}\">${index}</td> <td rowspan=\"${#test_fileArr[*]}\">${test_EvnAndDataArr[$b]}</td><td>${test_fileArr[$b]}</td><td>${test_fileSizeArr[$b]}</td><td>${test_fizeRowCntArr[$b]}</td></tr>" else row="${row}<tr> <td colspan=\"1\">${test_fileArr[$b]}</td> <td>${test_fileSizeArr[$b]}</td><td>${test_fizeRowCntArr[$b]}</td></tr>" fi done fi test_tableRowInfo["$index"]="$row" # ------------------------------------------------------------------------------------------------------------------------------------------- fi done index=`expr $index + 1` done #保证顺序 for ((x=0;x<${#prod_tableRowInfo[*]};x++)); do str1="${str1}${prod_tableRowInfo[$x]}" str2="${str2}${test_tableRowInfo[$x]}" done #var3="${prod_tableHead}${prod_tableRowInfo[*]}</table>" #var4="${test_tableHead}${test_tableRowInfo[*]}</table>" var3="${prod_tableHead}${str1}</table>" var4="${test_tableHead}${str2}</table>" #echo ${!prod_tableRowInfo[*]} #echo "${var3}" #echo "*************************************************************" #echo "${var4}" #echo ${!test_tableRowInfo[*]} sed -i "s#^var3=.*#var3=${var3}#g" $kettleConfigHome/sandMailVariate.properties sed -i "s#^var4=.*#var4=${var4}#g" $kettleConfigHome/sandMailVariate.properties # 发送邮件 sh /home/vmuser/linbo/kettleDemo/job/kjb/fileCpEvnEmailSend.sh