Skip to content

Instantly share code, notes, and snippets.

@stursby
Last active December 22, 2015 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stursby/5cc8dfbf6c51ee2b1964 to your computer and use it in GitHub Desktop.
Save stursby/5cc8dfbf6c51ee2b1964 to your computer and use it in GitHub Desktop.
Raspberry Pi boot SMS IP address script

Raspberry Pi boot SMS IP address script

Set environment variables

Open .bashrc

sudo nano ~/.bashrc

At the end of the file add two variables

TWILIO_ACCOUNT_SID=<your_key_here>
TWILIO_AUTH_TOKEN=<your_token_here>

Reload .bashrc file

source ~/.bashrc

Install the Twilio python lib

pip install twilio

Setup crontab

sudo crontab -e

Paste the following (make sure the path to the ip.py scipt matches)

@reboot /bin/sleep 60; /home/pi/scripts/boot/ip.py &
#!/usr/bin/python
# -*- coding: utf-8 -*-
import subprocess, os
from twilio.rest import TwilioRestClient
# Get hostname(s)
result = subprocess.check_output('hostname -I', shell=True).rstrip()
# Send SMS
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = TwilioRestClient(account_sid, auth_token)
message = client.messages.create(body=result,
to="+19522006798",
from_="+16122607545")
print message.sid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment