Crontab -e running script on startup (reboot script)

I am trying to get a python script to run at startup. @adam has been working with me on this and has been instrumental in boosting my knowledge and knowing what to look for on forums etc. I decided a new thread would be best.The script is designed to look for an input on pin 22 and reboot the Rpi3 when detected. The purpose is to allow my backup solar PLduino to reboot the Rp3 in case I lose communication with it.

I did as adam suggested and added @reboot python /home/pi/reboot8.py to crontab -e but the crontab is empty otherwise as if cron services is ignoring doesnā€™t use crontab it or something about the script wonā€™t be allowed to run on startup. A forum Running a Python + OpenCV script on reboot - PyImageSearch talks about virtual console using pi root user sudo /bin/bash. When I get to workon cv it gives me command not found. Do I need to download something like open cv3 or other?

#!/bin/bash
source /home/pi/.profile
workon cv
cd /home/pi/pi-reboot (maybe leave this at /home/pi where my file resides or create that folder and move file there?)
python reboot8.py(changed to show my file)

Any help is appreciated,
William

Hello sir,
I have like 10 or more scripts using @reboot in crontab.
I added them as you specify - @reboot and then path to filename.

I added them as the command that I use is: sudo crontab -e

I added them same way before and nothing happens.

Does the script work if you run it from the terminal? Running at reboot is not going to give you any output so if something is failing you will never know.

Hereā€™s the output from:
chmod a+x reboot.py (your script)
./reboot.py
Is this the correct mode to run in terminal?

your script:
lines 1 thru 4 import: command not found. line 5 ./rā€™ command not found. line 6 syntax error near unexpected token `(') def reboot(channel)
the other script (the one I found and modified pin assignment) gives the same basic " import: command not found " and lists some directories for mail process which may have been set up to email the coder the output when running the script for error checking. This makes me believe I need to trim down that one script or maybe yours needs tweaking?

thanks William

If you post the output Iā€™ll be able to tell you what you need to install. Without it itā€™s just guessing 1/4 libraries that need installed. time, os, sys, and rpi.gpio should all be installed by default on Jessie full.

Here tis

use the command python reboot.py

get back ā€œpin value: 0ā€ repeatedly. I applied 3.3v to pin and still 0.

Do you have a common ground between your power sources?

only one power source at this point, Rpi.

Iā€™d say at that point you need to figure out why the pin isnā€™t changing value. Check your connectors, make sure there really is 3.3v where you think there is, check to see if the pin is the right pin, etc.

Iā€™m connected with a cobbler and def has 3.3v. Verified correct pin. The other script I used will reboot when pull up on pin but like yours it will not work at reboot.

The other script is using bcm pin numbering and Iā€™m using board numbering. If I had to guess you are on the wrong pin. Thereā€™s no way one works and one doest, itā€™s using the same exact library.

Ok so my old brain was being dumb. Using a hit and miss procedure I found gpio 23 is actually pin 16(pin I chose in your script).

I couldnā€™t get it to run on startup/reboot so I added sudo python /home/pi/reboot.py & just before the last line in /etc/rc.local. Works like a champ.

A thought crossed my mind, crontab didnā€™t work for me because I actually wrote a new file. Should have: sudo nano /etc/crontab -e to edit the actual file. :thinking:

Thanks for your help. I was determined to find a way to prove your script works since obviously youā€™ve been at this longer than I.

William
Treat me like a really young student or dense old geezer and I shall learn wellšŸ˜Š

1 Like

You shouldnā€™t have to use sudo nano /etc/crontab -e. When you use the command crontab -e it will ask you to choose your editor and create the new file for you when you save.

Finally getting around to adding This reboot python script in this thread.

Credit goes to @adam for helping write this code. Took some forehead smacking but adam came thru and I got the code in the right place and when I click button to reboot Rpi it works flawlessly.

This python script was found on Stackoverflow.com forums. It is designed to reboot an Rpi remotely using another device by pulling up on a GPIO by use of a relay across GPIO input and 3.3v Ā· GitHub

William

1 Like