6月 072013
羽田先生がやってたやつ
Rapsberry Pi でIPアドレスをDMする | HADA HISAKAZU Personal Information.
twとpipeとcrontabでやってみる
インストール
% sudo gem install twuser:addで @shokai_log としてログインする。
% tw --user:add
下準備として、 Raspberry Piで使うアカウントにmentionを飛ばす。

さてIPアドレスをRaspberry Piから自分宛にDMする。
これを実行すればいい。自分宛の最新のmentionが @shokai からで、本文に「IP」という文字列が含まれている時に、自分のIPアドレスをDMで送り返す。
tw --user=shokai_log --format="#{user} #{text}" | tail -1 | grep -i "^shokai .*ip.*" && echo "`/sbin/ifconfig -a | grep "inet" | grep -v 127` `date`" | tw --pipe --user=shokai_log --dm:to=shokai
cronで5分ごとぐらいに実行すればいいと思う。
crontab -e
*/5 * * * * tw --user=shokai_log --format="#{user} #{text}" | tail -1 | grep -i "^shokai .*ip.*" && echo "`/sbin/ifconfig -a | grep "inet" | grep -v 127` `date`" | tw --pipe --user=shokai_log --dm:to=shokai
実行結果

DMがくる

何か別のこと(IPという文字列を含まないtweet)をmentionしない限り、何回もDMを飛ばしてくるので適当に止める。
