경로에 클라이언트 파일이 생성되었습니다. 이 파일의 데이터를 표 형식과 이메일 첨부 파일로 보내고 싶습니다. 도움을 받은 샘플 스크립트가 있는데, 그 결과는 다음과 같습니다.
#initialising variables
dt=`date +%Y%m%d`;
[email protected]
TO="[email protected]";
CC=""
BCC=""
SUBJECT="Manager Accounts KPI Results - $dt";
BOUNDARY="PARAEND";
set -x
File_path="/File_gen/data"
script_path="/File_gen/data"
Mail_Content="$File_path/Customer_KPI_Mail.ml"
Mail_Opener()
{
echo "From: "$FROM"
To: "$TO"
cc: "$CC"
bcc: "$BCC"
Subject: "$SUBJECT"
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=\"$BOUNDARY\"
--$BOUNDARY
Content-Type: text/html
<html>
<style>
table{
border-collapse:collapse;
}
caption{
margin:0;
padding:0;
#border:1px solid black;
}
th{
background-color:#BAFFBA;
}
</style>
<body>
<span id='notification'> <i> << This is an automated notification. please do not respond to this email.>> </i> </span> <br /> <br />
<div>
Hi All - <br /> <br />
Please find the results $dt .<br /> <br />
<table border=1 cellpadding=3>
<tr>
<th> Rule_Name </th>
<th> Lower_Variance </th>
<th> Upper_Variance </th>
<th> Current_Day_Variance </th>
<th> Result_Check </th>
</tr>
" > $Mail_Content
}
Mail_Closure()
{
echo "</table><br /> <br />
</div>
<div>Thanks, <br />
Global Team </div>
</body>
</html>" >> $Mail_Content
}
Table_Content_Designer()
{
col1="$1";
col2="$2";
col3="$3";
col4="$4";
col5="$5";
echo "<td> $col1 </td>" >> $Mail_Content
echo "<td> $col2 </td>" >> $Mail_Content
echo "<td> $col3 </td>" >> $Mail_Content
echo "<td> $col4 </td>" >> $Mail_Content
echo "<td> $col5 </td>" >> $Mail_Content
}
Mail_Opener;
cat "$script_path/cust_acct_check.txt" |sed 1d | while read line
do
line="$File_path"/"$line";
counter=1;
line_count=`wc -l $line | awk -F " " '{print $1}'`;
cat $line | while read data
do
col1=`echo $data | awk -F "," '{print $1}'`;
col2=`echo $data | awk -F "," '{print $2}'`;
col3=`echo $data | awk -F "," '{print $3}'`;
col4=`echo $data | awk -F "," '{print $4}'`;
col5=`echo $data | awk -F "," '{print $5}'`;
if [ $counter -gt 1 ]; then
if [ $counter -eq $line_count ];then
Table_Content_Designer "$col1" "$col2" "$col3" "$col4" "$col5";
echo "</tr>" >> $Mail_Content
counter=`expr $counter + 1`;
fi
if [ $counter -lt $line_count ];then
Table_Content_Designer "$col1" "$col2" "$col3" "$col4" "$col5";
echo "</tr>" >> $Mail_Content
echo "<tr>" >> $Mail_Content
counter=`expr $counter + 1`;
fi
else
counter=`expr $counter + 1`;
fi
done
done
Threshold_File="$File_path/cust_acct_check.txt"
if [ -s "$Threshold_File" ];then
echo "</table><br /> <br />
</div>
<div>The data file is alos located at Target path <br />
Please reach out to the GDMART <[email protected]> in case of any questions. <br /> <br /></div>
<div>Thanks, <br />
Global Team </div>
</body>
</html>
--$BOUNDARY
Content-Type: application;name="cust_acct_check.txt"
Content-Transfer-Encoding: base32
Content-Disposition: attachment; filename="cust_acct_check.txt"
" >> $Mail_Content
cat "$Threshold_File" >> $Mail_Content
else
Mail_Closure;
fi
cat "$Mail_Content" | sendmail -t
다음은 테이블 형식으로 넣으려는 csv 파일입니다.
#key_rule,Lower_variance,Upper_variance,Actual_value,Result_check
MGR_ACCT_CNT,0,9000,8,True
MGR_BAL_CHK,-0.035,0.035,0.063997,False
MGR_ACCT_COM,-1,1,1.170281,False