LoginSignup
1
1

More than 5 years have passed since last update.

メール受信時にコマンドを実行する

Posted at
  • 呼び出すスクリプトを用意
# vi /tmp/a.pl
#!/usr/bin/perl
use strict;
use warnings;

open my $fh, ">>/tmp/a.txt";
while(my $line = <STDIN>) {
        chomp $line;
        print $fh "$line\n";
}
close $fh;
# chmod +x /tmp/a.pl
  • /etc/aliasesに対象アカウントを記載(このアカウントは存在していなくてよい)
# vi /etc/aliases
tester:         "|/tmp/a.pl"
# newaliases
  • メールを送信
$ echo "test" | mail -s "title" -S "smtp=smtp://localhost:25" -r from@example.com tester@`hostname`
  • スクリプトが実行される
# cat /tmp/a.txt
Subject: title
User-Agent: Heirloom mailx 12.5 7/5/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

test

メール受信で自動的にスクリプトを実行する | 情シスハック

設定ファイル:/etc/aliases: UNIX/Linuxの部屋

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1