I wrote a simple python script which, when executed, gets my BeagleBone Black's ip address and sends it to my email address, preventing me from having to plug the board into my laptop, get the ip, unplug it, and then remotely SSH in. Here is the script
#!/usr/bin/python
"""Find own ip address and email it."""
import socket
import datetime, time
import sys
failed = 1
while(failed):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8",80))
my_ip = s.getsockname()[0]
s.close()
failed = 0
except SocketError:
print sys.exc_info()[0]
except:
print error
time.sleep(5)
# Import smtplib for the actual sending function
import smtplib
# Import the email modules we'll need
from email.mime.text import MIMEText
msg = MIMEText("cta_BBB_1 ip address: %s" % my_ip)
me = '<outgoing message email address>'
you = '<incoming message receiver>'
msg['Subject'] = 'cta_BBB_1 ip address at ' + str(datetime.datetime.now())
msg['From'] = me
msg['To'] = you
# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP('<server_name>', <server_port))
s.login('<login>', '<password>')
s.sendmail(me, [you], msg.as_string())
s.quit()
The script works perfectly if I just run it on the BBB. I then made the script executable and wrote a cron job to fire it, which looks like this (ignore the second line, that deals with resetting the date/time on the BBB):
@reboot /usr/bin/python /home/root/cta_stuff/cta_boot_send_ip.py
30 * * * * /usr/bin/ntpdate-sync silent
Which does show up if I run crontab -l
.
So, when I hard reboot (via the reset button), reboot via ssh, or halt the board and then turn it back on, the cron job does not fire the script (i.e. no email is received with the ip address). I have checked formatting, permissions, etc., on everything I can think of involved in this task on the BBB. If anyone has any idea why it is not working, I would really appreciate some help, as I am totally stumped.
Also, I am currently using the BBB-eMMC-flasher-2013.06.06.img
image for Angstrom.