1

I need a command to run at reboot. This command is called script.sh

#!/bin/bash
ibeacon scan | /home/pi/test.py

This command pipes input to a python program I wrote called test.py.

#!/usr/bin/python
import fileinput
import socket
import requests

for line in fileinput.input():
   if line.startswith('UUID:'):
      line = line.strip()
      a = line.split(' ')[1]
      b = line.split(' ')[3]
      c = line.split(' ')[5]
      d = line.split(' ')[7]
      e = line.split(' ')[9]
      f = socket.gethostname()
      payload = {'uuid': a, 'major': b, 'minor': c, 'power': d, 'rssi': e, 'hubname': f}
      r = requests.get('http://httpbin.org/get', params=payload)
     # print(r.url)     ##Print the URL
   elif line.startswith('iBeacon'):
      print "Starting script..."
      continue
   else:
      print "Error: invalid input, closing..."
      break

The problem is the program is not running when I check the processes.The syslog file states that it started the command on reboot, but it is not running.

Aug 19 22:23:35 raspberrypibeacon /USR/SBIN/CRON[2089]: (root) CMD (/home/pi/script.sh > /dev/null 2>&1)

my crontab entry looks like this

@reboot /home/pi/script.sh > /dev/null 2>&1

Is the problem with cron or with my program? My program works fine when run from the command line, but not when executed by cron.

  • 1
    I'd find a line to add to the script to echo something somewhere, and or write another tiny script to have cron execute on reboot, just to prove cron is working. I suspect the problem is something with the environment when run from cron. When you run it from the command line you are a logged in user with some environment variables set during your login. The environment cron is spinning up may need some tweaking. – Tyson Aug 20 '14 at 01:57
  • Try doing: ps -A | grep python If the script is running it'll show up as: 1976 ? 00:00:00 python – Jared L. Sep 09 '14 at 02:04
  • Maybe you should try to enable cron logs as it is described here. – Morgan Courbet Sep 09 '14 at 07:03

0 Answers0