Page 1 of 1

Pi3B+ crontab not running raspistill

Posted: Fri May 11, 2018 8:40 pm
by peggyopal
I have a script that is run as a cron job

Code: Select all

(crontab -l 2>/dev/null; echo "@reboot /home/pi/PicsOnSticks/picScript.sh") | crontab -
The script runs perfectly, with one exception, it doesn't take a picture (which is its one goal in "life".)

Code: Select all

raspistill -q 100 -n -o ${MACHINEID}-${NUM}.jpg
This script has been successfully taking photos on RPi0s and RPi3Bs but it's not working on RPi3B+s, did something change that I'm missing?

Edit: The script takes a photo and stores it in a directory so it can be analyzed at a later time. Also, I'm using Stretch.

Re: Pi3B+ crontab not running raspistill

Posted: Wed May 16, 2018 3:05 pm
by peggyopal
Figured it out.
The script is running from

Code: Select all

crontab -e
and

Code: Select all

sudo crontab -e
This is causing the script to be called twice and the photo is failing because the camera is trying to take two photos at the same time.

Re: Pi3B+ crontab not running raspistill

Posted: Wed May 16, 2018 3:14 pm
by n67
Two commands you should never, ever, ever, ever execute:

1) sudo rm -rf /

2) sudo crontab -e

Re: Pi3B+ crontab not running raspistill

Posted: Wed May 16, 2018 3:20 pm
by peggyopal
n67 wrote:
Wed May 16, 2018 3:14 pm
2) sudo crontab -e
I didn't execute that ¯\_(ツ)_/¯ but good to know, thank you! I'll make sure that

Code: Select all

crontab -e
is the one running the script. Is there a reason that's preferred over sudo?

Re: Pi3B+ crontab not running raspistill

Posted: Wed May 16, 2018 3:33 pm
by RaTTuS

Code: Select all

sudo crontab -e
edits the cron for the root user

Code: Select all

crontab -e
edits the cron for the current user

Re: Pi3B+ crontab not running raspistill

Posted: Wed May 16, 2018 3:40 pm
by peggyopal
Okay, but is there a reason that editing the current user is preferred over editing the root user?

Re: Pi3B+ crontab not running raspistill

Posted: Wed May 16, 2018 10:04 pm
by DougieLawson
peggyopal wrote:
Wed May 16, 2018 3:40 pm
Okay, but is there a reason that editing the current user is preferred over editing the root user?
If the script you're running from cron doesn't need elevated privileges then don't run it from the root crontab. Don't use sudo when you don't need it. Don't run as root when you don't need it. That's part of Linux Security 101.

Re: Pi3B+ crontab not running raspistill

Posted: Wed May 16, 2018 10:42 pm
by n67
DougieLawson wrote:
Wed May 16, 2018 10:04 pm
peggyopal wrote:
Wed May 16, 2018 3:40 pm
Okay, but is there a reason that editing the current user is preferred over editing the root user?
If the script you're running from cron doesn't need elevated privileges then don't run it from the root crontab. Don't use sudo when you don't need it. Don't run as root when you don't need it. That's part of Linux Security 101.
That's half of the answer - and the most important half. Since nothing in this current thread requires root privs to run, there is, of course, no reason to run it as root.

The other half is that if you do need root privs in a cron job, then there are two ways to do it:

1) Put it in root's crontab - now you have two things to keep track of - which leads to confusion as we see this thread. Don't do this!

2) Put it in pi's crontab - and use 'sudo' like you normally do when you need to run stuff as root when running on the Pi.

Note: Yes. I am assuming the default configuration with "passwordless" sudo. If, as many of the big time forum posters do, you remove "passwordless" sudo, then this changes (and in that case, you ought to know what you are doing). But in the default config, it is better to keep everything in a single file. As already mentioned, this keeps things simple and trackable - and avoids the confusion that caused the problem in this thread.