Executing scripts at boot [CLOSED]

Forum about Parallella boot process, linux kernel, distros, SD-cards, etc.

Executing scripts at boot [CLOSED]

Postby maynarde » Mon Aug 04, 2014 12:13 am

****** IGNORE THIS, READ BELOW FOR SOLUTION *********

Hope this is the proper place to post this.

I have the 7010 running with the HDMI build (although the headless works just fine as well). I do have the USB issue but if I wait 30 seconds after removing power to reboot, it shows up. So this is really just a newbie linux question.

I am trying to have my Parallella email me its internal ip address at boot time. I have done similar things on my RPi (Rasberian) and Beaglebone Black using a python script (same as on elinux.org). I have modified /etc/rc.local to include a "sleep 30" at the start. It just seems like the rc.local script never executes; the script works fine from the command line. my python script has execute permission. I have also tried crontab as root using the "@restart" parameter but that does not seem to fire either. I have made sure to use absolute directories in case PATH is not available.

I must be doing something simply wrong here - any ideas? Should I be looking into upstart?
Last edited by maynarde on Mon Aug 04, 2014 1:11 am, edited 1 time in total.
maynarde
 
Posts: 24
Joined: Sat Jul 19, 2014 8:26 pm

Re: Executing scripts at boot

Postby maynarde » Mon Aug 04, 2014 12:54 am

Looks like I fixed my own problem! Here are the listings (I should thank the original poster of this but forgot to write it down :oops: ):

#!/usr/bin/python

"""Find own ip address and email it."""

import socket
import datetime, time
import sys

time.sleep(45) #avoid timing issues
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("Parallella ip address: %s" % my_ip)


me = '<sending address>'
you = '<destination address' # I send it using an email-to-sms gateway at ATT

msg['Subject'] = 'Parallella 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('smtp.gmail.com', 587)
s.ehlo()
s.starttls() # This is VERY important - many scripts on Web skip this (older posts)
s.ehlo
s.login('<your gmail logon>', '<your gmail password') # This will be in plaintext on your machine.
s.sendmail(me, [you], msg.as_string())
s.quit()

***** Save this file as /home/linaro/send_ip.py ********
This step is what made it work for me - I guess that /home/linaro/Documents doesn't exist yet!

I then used a program Webmin that makes life for a newbie SO MUCH EASIER to create the cron job that fires at boot. Make sure to use fully qualified paths to python and your script. Make sure to run as "root" not "linaro"


The other thing is that the cron only fires on a power cycle - if you "sudo shutdown -r now" to reboot, it does not fire. If, however, you "sudo shutdown -h now" and cycle power, you get that magic notification from your cell phone.
Last edited by maynarde on Mon Aug 04, 2014 1:11 am, edited 1 time in total.
maynarde
 
Posts: 24
Joined: Sat Jul 19, 2014 8:26 pm

Re: Executing scripts at boot

Postby maynarde » Mon Aug 04, 2014 1:02 am

I am a liar - it seems to work on the reboot as well. Apparently your mileage may vary.
maynarde
 
Posts: 24
Joined: Sat Jul 19, 2014 8:26 pm

Re: Executing scripts at boot [CLOSED]

Postby maynarde » Thu Aug 07, 2014 4:54 am

maynarde
 
Posts: 24
Joined: Sat Jul 19, 2014 8:26 pm


Return to Linux/U-Boot

Who is online

Users browsing this forum: No registered users and 11 guests