packages から fetchmail をインストールし、設定ファイルを作製。
# pkg_add fetchmail-5.4.1.tgz # vi /root/.fetchmailrc
poll ISP1のPOPサーバ proto pop3 user "ISP1のアカウント" there with pass "ISP1のパスワード" is ローカルのアカウント1 poll ISP2のPOPサーバ proto pop3 user "ISP2のアカウント" there with pass "ISP2のパスワード" is ローカルのアカウント2
# chmod 600 /root/.fetchmailrc
10分おきに取得する cron 設定をする。
0,10,20,30,40,50 * * * * /usr/local/bin/fetchmail --silent --fetchmailrc /root/.fetchmailrc
定期的に yi.org へアドレス登録 (そうしないと使用していないとして登録削除されるから)。
TrH Tools で作成した TrH.pm を用いて、 次のようなスクリプト yi を作成。yi と TrH.pm とを同一ディレクトリに置く。
#!/usr/local/bin/perl $PROGRAM = 'Izayoi'; $VERSION = '1.00'; BEGIN { ($bin_dir = $0) =~ s|[^/]+$||; $bin_dir = './' unless $bin_dir; } $url = 'http://www.yi.org/bin/dyndns.fcgi?ipaddr='; $user = '登録名'; $pass = 'パスワード'; $nic = 'インタフェース'; $addr = '0.0.0.0'; use lib "$bin_dir"; use TrH qw(agent basicauth request rsphead error quit); open(IFCONF, "/sbin/ifconfig $nic |") || die "cannot read IP address."; while (<IFCONF>) { if (/inet ([0-9\.]+) /) { $addr = $1; } } if ($addr eq '0.0.0.0') { print "cannot recognize IP address.\n"; exit; } $trh = new TrH; $trh->agent("$PROGRAM/$VERSION ".$trh->agent); $trh->basicauth($user, $pass); $content = $trh->request('GET', $url.$addr); if ($content) { $content =~ s/\<.+?\>//g; $content =~ s/^\n|\n$|\n(\n\n)/$1||''/ges; print $content."\n"; } $trh->quit; exit;
これを週一で実行する cron 設定をする。
0 2 * * 1 /home/net/bin/yi