Raspberry PiのIPアドレスを自動でメールに送信する(CNS編)


SFC生にとってラズパイは無くてはならない

だがCNSでデモしようとするとIPアドレスの確認がめんどい。
自動的ににIPアドレスをメールで送ってほしい。

sSMTPを導入

sudo apt-get install sSMTP

sSMTPを設定する

sudo nano /etc/ssmtp/ssmtp.conf

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
[email protected]

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.sfc.keio.ac.jp:465

# Where will the mail seem to come from?
rewriteDomain=sfc.keio.ac.jp

# The full hostname
hostname=hoge

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
#FromLineOverride=YES

AuthUser=ログイン名
AuthPass=メールパスワード
UseTLS=YES

ネットワークが上がったら自動でメールを送るスクリプトを書く

sudo nano /etc/network/if-up.d/ipmail

#! /bin/bash
sleep 30s
ip addr | mail -s "ip is..." "送りたいアドレス@sfc.keio.ac.jp"

30秒くらいスリープを入れないと、ネットが上がってもIPアドレスが取れてなかったりして送信に失敗するので。