Trying to run a python script from ubuntu crontab Trying to run a python script from ubuntu crontab tkinter tkinter

Trying to run a python script from ubuntu crontab


I'm not sure what you expect to happen here. The cronjob won't have access to a display where it can display the GUI, so the button will never be displayed, so print_this will never be run

FWIW, when I tried to run your code I got an error:

  File "./t.py", line 4    def __init__(self,parent):      ^IndentationError: expected an indented block

Not sure if that's just caused by copy/paste into the page or if it's a real problem with your code.


In linux mint 17 I had to do the following:

Make the scripts executable
~$chmod +x script.py

You have to enable X ACL for localhost to connect to for GUI applications to work
~$ xhost +local:

Add the following line in the crontab "env DISPLAY=:0.0"
* * * * * env DISPLAY=:0.0 /usr/bin/python /your-script-somewhere.py

And one more line to crontab ">/dev/null 2>&1"
* * * * * env DISPLAY=:0.0 /usr/bin/python /your-script-somewhere.py >/dev/null 2>&1

you can check errors in /var/log/syslog file
~$ tail -20 /var/log/syslog

more info:
https://help.ubuntu.com/community/CronHowto


I use crontab to run a bash file

30 12 * * 1,2,3,4,5 /home/edward/SSF/SW/EODWD.sh

in termanal -- use crontab -e

the bash file executes as many other programs as you wish

/home/edward/SSF/SW/EODWD.py >> /home/edward/Desktop/eodmail.logwait

this example also sends all print statements in EODWD.py to a log file automatically

the wait statement forces competion before taking the next command

this works ONLY IF both files ( *.py & *.sh ) are made executable