Perl sendmail附加日志文件匹配date格式

我想发送匹配date格式的日志文件,例如YYYY-MM-DD – *。log作为Perl脚本中的附件。 在BASH中,这可以通过以下方式轻松完成:

[ -f $DIR/explog/$(date "+%Y-%m-%d")-*-host1.log ] && mutt -s "subject here" \ -a $DIR/explog/$(date "+%Y-%m-%d")-*-host1.log [email protected] </dev/null 

出于某种原因,我需要在Perl脚本中这样做。 Perl脚本的主要部分如下,我想在电子邮件中添加日志文件。 任何想法?

顺便说一句,这个Perl脚本被称为来自BASH shell脚本的电子邮件警报,所以如果有任何方法将文件传递给perl脚本,例如/ usr / bin / perl $ DIR / emailAlert.pl file1.log file2.log将服务于目的。 请指教,谢谢。

 #!/usr/bin/perl -w use MIME::Lite; $msg = MIME::Lite->new( From => 'sender\@example.com', To => 'recipient\@example.com', Subject => 'subject here', Type => 'multipart/mixed' ); $msg->attach( Type => "text/plain", Path => $tmpMsg, Filename => $tmpMsg, Disposition => "attachment" ); $msg->send('smtp', 'mailserver.example.com', Timeout => 60); 

您可以在$log1 = $ARGV[0]$log2 = $ARGV[1]等语句中使用参数,并将它们分配到$msg->attach部分。 你可以像这样使用它:

  while (@ARGV) { $msg->attach( 'Type' => 'text/plain', 'Path' => shift @ARGV ); }