pd2
Posts: 41
Joined: Sun Jun 05, 2016 11:42 am

Crontab setup in LDXE desktop

Fri Jun 10, 2016 9:12 pm

I have only the following line in my Crontab file and it doesn't seem to work.
Give me some clues please before this Pi2 gets taken into the cellar and beaten to death.

@reboot sudo python /home/pi/Downloads/astart02.py &
--- followed by a blank line

W. H. Heydt
Posts: 10769
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Crontab setup in LDXE desktop

Sat Jun 11, 2016 1:38 am

What does your Python program do? Do you expect to see output from it on your display?

Programs run from crontab do know where anything is unless you tell them (there is no environment). The following shell scrip will display a digital clock when run as a cron job:

Code: Select all

#!/bin/bash

PATH=/home/pi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
export DISPLAY=:0.0

dclock -geometry 400x200+200+10
The path is for general setup. Since you're using an absolute path, you probably don't need a PATH statement. The "export DISPLAY" sets things up to display the output on the default display (an RPF 7" touchscreen is the intended use).

swampdog
Posts: 230
Joined: Fri Dec 04, 2015 11:22 am

Re: Crontab setup in LDXE desktop

Sat Jun 11, 2016 3:19 am

'crontab' isn't GUI independant.

Code: Select all

[email protected] ~ $ crontab -l
PATH=/usr/local/sd/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
#------------------------------------------------------------------------------
#min    hrs     dom     mon     dow     /path/to/cj
#------------------------------------------------------------------------------
30	07	*	*	*	cjx svr-fw list
*/5	*	*	*	*	cjy svr-fw chk-resolv
#*/20	*	*	*	*	cjx svr-ipdhcpw
#------------------------------------------------------------------------------
$ EDITOR="nano -w" crontab -e

..so "* * * * * touch /tmp/z" should tell you if you've got it right, once a minute.

User avatar
rpdom
Posts: 15005
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Crontab setup in LDXE desktop

Sat Jun 11, 2016 5:21 am

pd2 wrote:I have only the following line in my Crontab file and it doesn't seem to work.
Give me some clues please before this Pi2 gets taken into the cellar and beaten to death.

@reboot sudo python /home/pi/Downloads/astart02.py &
--- followed by a blank line
The & isn't required, as crontab jobs always run in the background.

I always log the output of cron jobs, so I can see what they have been doing

Code: Select all

@reboot sudo  python  /home/pi/Downloads/astart02.py >/tmp/astart02.out 2>/tmp/astart02.err
That will create two files in /tmp. astart02.out which contains the normal output of the script, and astart02.err which will contain any error messages.

pd2
Posts: 41
Joined: Sun Jun 05, 2016 11:42 am

Re: Crontab setup in LDXE desktop

Sat Jun 11, 2016 8:41 am

W. H. Heydt wrote:What does your Python program do? Do you expect to see output from it on your display?

Programs run from crontab do know where anything is unless you tell them (there is no environment). The following shell scrip will display a digital clock when run as a cron job:

Code: Select all

#!/bin/bash

PATH=/home/pi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
export DISPLAY=:0.0

dclock -geometry 400x200+200+10
The path is for general setup. Since you're using an absolute path, you probably don't need a PATH statement. The "export DISPLAY" sets things up to display the output on the default display (an RPF 7" touchscreen is the intended use).
Thanks for the replies. I am working through them. So I replaced my line with your file and I see nothing new on the desktop. Should I? I expected to see a clock!

My program stores times and directions for the window blinds and closes solenoids to control the remote. Every time it sends a command it writes a data row line to the screen as a status check. It runs perfectly reliably from the console but we're going on holiday for a month and I would like the program to restart after a power fail!

pd2
Posts: 41
Joined: Sun Jun 05, 2016 11:42 am

Re: Crontab setup in LDXE desktop

Sat Jun 11, 2016 8:56 am

rpdom wrote:
pd2 wrote:I have only the following line in my Crontab file and it doesn't seem to work.
Give me some clues please before this Pi2 gets taken into the cellar and beaten to death.

@reboot sudo python /home/pi/Downloads/astart02.py &
--- followed by a blank line
The & isn't required, as crontab jobs always run in the background.

I always log the output of cron jobs, so I can see what they have been doing

Code: Select all

@reboot sudo  python  /home/pi/Downloads/astart02.py >/tmp/astart02.out 2>/tmp/astart02.err
That will create two files in /tmp. astart02.out which contains the normal output of the script, and astart02.err which will contain any error messages.
Ah ha! Now we're getting somewhere... I got an error message "sudo: /user/bin/python: command not found" which I guess means that my path is wrong or it needs a file suffix like .exe? However there is a python executable in this exact path!
Or does it need a path for sudo? Totally confused now.

Return to “Beginners”