2

I am trying to automate QGIS (2.18.4) standalone scripts in ubuntu using crontab. My scripts execute well when running from command, but fail if I put in crontab.

from qgis.core import *
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from qgis.gui import *
app = QApplication([])
QgsApplication.setPrefixPath("/usr", True)
QgsApplication.initQgis()

In crontab, it fails at app = QApplication([]). Crontab gives error as

: cannot connect to X server

How to make my QGIS standalone script run in crontab?

ahmadhanb
41.8k5 gold badges55 silver badges110 bronze badges
asked Mar 6, 2017 at 14:10
0

1 Answer 1

3

This problem is actually not related to this community, you should ask in unix.stackexchange.com to get better answers.

To run a GUI command with a cronjob, you'll have to tell cron what display the program should use:

export DISPLAY=:0

:0 is the default Display. If you like the program to run on other display, please change the number accordingly (e.g. :1, :2, etc).

Your cron command will look like this:

* * * * * export DISPLAY=:0 && python /path/to/your/command.py
answered Mar 6, 2017 at 14:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.