1

I am trying to run a script at bootup. I am autologing to desktop.

Script1: pibot.sh

#!/bin/bash
sudo python /home/pi/rpibot.py

Script2: rpibot.py

import rrb2 as rrb
from rrb2 import *
import pygame
import sys
from pygame.locals import *
import time

rr = RRB2()
running = True
leds_on = False
pygame.init()

screen = pygame.display.set_mode((620, 480))

pygame.display.set_caption('RaspiRobot')
pygame.mouse.set_visible(0)

GPIO.setwarnings(False)
while True:
    distance = rr.get_distance()
    if distance < 10 and running:
        rr.stop()
           # if not running:    
        rr.set_oc1(leds_on)
        rr.set_oc2(leds_on)
        time.sleep(0.6)
        leds_on = not leds_on

    for event in pygame.event.get():
        if event.type == QUIT:
            sys.exit()
        if event.type == KEYDOWN:
            if event.key == K_UP:
                rr.forward()
                rr.set_oc1(True)
                rr.set_oc2(True)
            elif event.key == K_DOWN:
                rr.set_oc1(True)
                rr.set_oc2(True)
                rr.reverse()
            elif event.key == K_RIGHT:
                rr.set_oc1(False)
                rr.set_oc2(True)
                rr.right()
            elif event.key == K_LEFT:
                rr.set_oc1(True)
                rr.set_oc2(False)
                rr.left()
            elif event.key == K_SPACE:
                rr.stop()
                rr.set_oc1(False)
                rr.set_oc2(False)  

Both work in command line in terminal, but do not work on boot. I have tries putting pibot.sh in rc.local and get error unable to read with the update command.

  • Your question is unclear. Try editing /etc/rc.local (which contains additional information). You do not need sudo in startup scripts, as these are run as root. If you want to run a python script, forget the /bin/bash and use #!/usr/bin/env python in your python script. NOTE that running scripts which assume PATH or screen is unlikely to be successful. Maybe this should be run after login. – Milliways Nov 9 '14 at 0:37
3

The problem may be $PATH. It likely isn't set to anything when rc.local runs, and since the shells spawned there aren't interactive or login shells, bash does not source any configuration (see INVOCATION in man bash).

A solution in this case may be to simply add to the top of /etc/rc.local:

export PATH=/bin:/usr/bin:/sbin:/usr/sbin

If you want /usr/local/bin or anything special in that, use that too. This is the $PATH that will be used by the script and anything it spawns.

The other option is to use absolute paths for every command that is not a shell built-in, both in rc.local and anything it spawns.

Init scripts including rc.local should exit quickly, so you should background the python script with &. You do not need the intermediate shell script with sudo, just put:

/usr/bin/python /home/pi/rpibot.py &

in rc.local. If you've exported $PATH (which you'll need to if rpibot.py uses it at all), you can leave out /usr/bin.

If it still does not work, the easiest way to debug it is to log to a file from rpibot.py.

0

You need to place a command to run the file in your .bashrc/.bashrc_profile scripts. just put the command at the bottom and save then reboot. make sure your have adjusted to permissions of the file you intend to run or have them set accordingly to begin with.

  • if you need to auto login then make adjustments to you inittab file in the root dir – 1'' Nov 10 '14 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.