在跑仿真时,尤其是后仿,往往需要耗时很长时间,少则几小时,多则几天,我们不可能一直守在电脑前,因此,设置自动邮件提醒很有必要;
通过搜索仿真sim.log中 FAIL 、ERROR 、PASS等字符,来判断仿真结果,将其记录到report.log中,包括仿真log路径,时间等信息,并实时发送邮件;
#!usr/bin/perl -w
use strict ;
my $result ;
my $now = `date +%Y-%m-%d' '%H:%M:%S`;
check_PASS_or_FAIL(); #搜索
pwd(); #打印路径
sendmail(); #发送邮件
sub check_PASS_or_FAIL{
open(OUTFILE, ">report.log");
if(`grep -P "FAIL|ERROR" ./sim.log`){
$result = $now . "FAIL\n";
print OUTFILE ($result);
}
elsif(`grep -P "PASS|SUCCESS" ./sim.log`){
$result = $now . "PASS\n";
print OUTFILE ($result);
}
else {
$result = $now . "Unknow\n";
print OUTFILE ($result);
}
}
sub pwd{
system("echo \"\`pwd\`\n\" >>report.log ");
}
sub sendmail{
system("mail -s \"END\" \"xxx\@xxx.com\" < report.log");
}
邮件结果:
2022-01-28 18:52:35
PASS
/home/perl/log
“mail test“为邮件内容,test为邮件主题
echo “mail test”|mail -s test xxx@xxx.com
将file中的内容发送至邮件:
mail -s test xxx@xxx.com< file
给多个用户发送邮件
mail -s test -c xxx@xxx.com xxx@xxx.com< file
将file文件内容发送给收件人xxx1@xxx1 并抄送给 xxx2@xxx2 和 xxx3@xxx3
mail -s test -c “xxx2@xxx2 xxx3@xxx3" xxx1@xxx 1< file