Skip to content

Instantly share code, notes, and snippets.

@mmaz
Last active April 27, 2016 22:04
Show Gist options
  • Save mmaz/f7ddb41a1b62c5cf1c22 to your computer and use it in GitHub Desktop.
Save mmaz/f7ddb41a1b62c5cf1c22 to your computer and use it in GitHub Desktop.
Intel Edison startup script
  • add ipaddr.py to /home/root/ and run chmod +x ipaddr.py
  • Add ipaddr.service to /lib/systemd/system (note: lib not etc)
  • test it:
$ systemctl daemon-reload
$ systemctl start ipaddr.service
$ systemctl status ipaddr.service
  • make it run on startup:
$ systemctl enable ipaddr.service
  • open gmail, run $ reboot and wait a few minutes (to allow for potential restarts)

hattip: https://communities.intel.com/message/255137

#!/usr/bin/python
import subprocess
import smtplib
import socket
from email.mime.text import MIMEText
import datetime
to = '****************************************'
gmail_user = '********************************'
gmail_password = '****************************'
smtpserver = smtplib.SMTP('smtp.gmail.com', 587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(gmail_user, gmail_password)
today = datetime.date.today()
p=subprocess.Popen('ifconfig',shell=True,stdout=subprocess.PIPE)
ifconfig = p.communicate()
p=subprocess.Popen('ip route list',shell=True,stdout=subprocess.PIPE)
iproutelist = p.communicate()
res = iproutelist[0] + '\n\n' + ifconfig[0]
msg = MIMEText(res)
msg['Subject'] = 'Intel Edison: %s' % today.strftime('%b %d %Y')
msg['From'] = gmail_user
msg['To'] = to
smtpserver.sendmail(gmail_user, [to], msg.as_string())
smtpserver.quit()
[Unit]
Description=ipaddr
Wants=network-online.target
After=network.target network-online.target
[Service]
ExecStart=/home/root/ipaddr.py
Restart=on-failure
RestartSec=30s
# read about on-failure: http://www.freedesktop.org/software/systemd/man/systemd.service.html
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment