I want to send log files matching date format, e.g. YYYY-MM-DD-*.log as attachments in Perl script. In BASH, this can be easily done by:
[ -f $DIR/explog/$(date "+%Y-%m-%d")-*-host1.log ] && mutt -s "subject here" \ -a $DIR/explog/$(date "+%Y-%m-%d")-*-host1.log email@example.com </dev/null
For some reason, I need to do this in Perl script. Main part of the Perl script is as below, I want to add log files in the emails. Any idea?
BTW, this Perl script is called as a email alert from BASH shell script, so if there is any method to pass files to perl script e.g. /usr/bin/perl $DIR/emailAlert.pl file1.log file2.log would serve the purpose. Please advise, thanks.
#!/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);