Redirect emails using alias script

Redirect emails using alias script

# vim /etc/aliases
command: |/bin/grep Subject >> /tmp/emailgrep.txt
commandperl: |/bin/test.pl

Pay attention on the permissions the email system will use the mail account, so set the permissions on the script

test sending the emails
# echo “test email 123” | sendmail command@localhost

Keep looking into the log:
# tail -f /var/log/syslog

Well if the stdin goes to Perl, baby you can do anything!
my test.pl is just a dumb one:

@lines = <STDIN>;
foreach $line (@lines) {
open FILE, “+>>”, “/tmp/emails.txt” or die $!;
print FILE $line;
}
close FILE

Leave a Reply

Your email address will not be published. Required fields are marked *

VAMOVE *

*