peggyopal
Posts: 9
Joined: Tue Jan 30, 2018 4:16 pm

Pi3B+ crontab not running raspistill

Fri May 11, 2018 8:40 pm

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.

peggyopal
Posts: 9
Joined: Tue Jan 30, 2018 4:16 pm

Re: Pi3B+ crontab not running raspistill

Wed May 16, 2018 3:05 pm

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.

n67
Posts: 788
Joined: Mon Oct 30, 2017 4:55 pm

Re: Pi3B+ crontab not running raspistill

Wed May 16, 2018 3:14 pm

Two commands you should never, ever, ever, ever execute:

1) sudo rm -rf /

2) sudo crontab -e
"L'enfer, c'est les autres"

If a post offends you, just put that poster on your foes list, and be done with it (and with them).

To do otherwise, risks being banned.

peggyopal
Posts: 9
Joined: Tue Jan 30, 2018 4:16 pm

Re: Pi3B+ crontab not running raspistill

Wed May 16, 2018 3:20 pm

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?

User avatar
RaTTuS
Posts: 10061
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Pi3B+ crontab not running raspistill

Wed May 16, 2018 3:33 pm

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
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

peggyopal
Posts: 9
Joined: Tue Jan 30, 2018 4:16 pm

Re: Pi3B+ crontab not running raspistill

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?

User avatar
DougieLawson
Posts: 33623
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Pi3B+ crontab not running raspistill

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.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

n67
Posts: 788
Joined: Mon Oct 30, 2017 4:55 pm

Re: Pi3B+ crontab not running raspistill

Wed May 16, 2018 10:42 pm

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.
"L'enfer, c'est les autres"

If a post offends you, just put that poster on your foes list, and be done with it (and with them).

To do otherwise, risks being banned.

Return to “Add-ons”

Who is online

Users browsing this forum: Paeryn and 3 guests