1

I have a script which runs a Java GUI application using "java -jar app.jar". I have added the script to the crontab to run every minute, check the processlist if the application is up. If it isn't it should start the application.

However, it only starts the process, but not the GUI. I have added "export DISPLAY=:0" to the top of the script, but that didn't help.

How do I make cron run the program as if I am starting it myself?

Thanks

2 Answers 2

4

This page explains how to run a GUI app using cron:

To run GUI application using cron in the command section replace the command name part the following way

env DISPLAY=:0 gui_appname

The env DISPLAY=:0 portion will tell cron to use the current display (desktop) for the program "gui_appname".

For example to run the rtorrent client(A terminal based popular torrent client in Linux) the crontab looks like this

# m h  dom mon dow   command
47 09 18 11 * env DISPLAY=:0 gnome-terminal -e rtorrent
1
  • 1
    I have found that example, but couldn't figure out what the gui_appname is for an application run via "java -jar app.jar".
    – nanoman
    Apr 23, 2012 at 12:41
0

For the sake of completeness and the Question from @nanoman in the comments, you can easily link the cron to a .sh file which starts you java application e.g. like this:

@reboot sleep 15; env DISPLAY=:0 /path/to/.sh

with a script which then starts, in my case, a JavaFX application on my touchscreen.

#!/bin/sh
java --your-arguments -jar /path/to/jar/file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .