Quantcast
Channel: OKWAVE 最新質問(OS(技術者向け)/233)【本日】
Viewing all articles
Browse latest Browse all 9758

ラズパイ起動時にIPアドレスをメールで取得したい

$
0
0
raspberry piの操作などは自分のwindows PCからTeraTermのSSHでログインして行いたいと思っています。 そこで、ラズパイに電源を入れてOSが起動完了したら、自分のメールアドレス宛にDHCPサーバから取得したIPを通知してほしいと思い、次のサイトのサンプルコード例を参考にしました。 IPアドレスの通知 https://raspberrylife.wordpress.com/2013/02/06/ip%e3%82%a2%e3%83%89%e3%83%ac%e3%82%b9%e3%81%ae%e9%80%9a%e7%9f%a5/ @tokoyaさんから メール送信アカウントは自分の所有するgmailアカウントを使用しています。 ここで作成したMyIP.pyのpythonコードを pi@raspberrypi $sudo python /home/pi/PythonProjects/MyIP.py これで実行したところ、自分のメールアカウントにIPの通知ができることを確認しました。 そこで、電源起動時にこのコードを動作させるために sudo nano /etc/rc.local で、次のようにrc.local内にMyIP.pyを自動起動するように設定しましたが、電源投入時にメールが送信されてきません。 修正方法等をご教示頂きますよう、よろしくお願い致します。 #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # Print the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" fi sudo python /home/pi/PythonProjects/MyIP.py exit 0

Viewing all articles
Browse latest Browse all 9758

Latest Images

Trending Articles

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>