Ubuntu – How to start a GUI application from cron


I need to run a Java applet from a Firefox. The problem is, I need to run this Firefox from a cron. If I run from the command line and its work fine, but when put the command in the cron it failed:

*/1 * * * * firefox http://domain.com/iqms/packetloss/iqmspacket2.html

Best Answer

  • Cron runs in an environment that knows nothing about the display manager ($DISPLAY isn't set). Your terminal window that you've been testing in has this set for it. If you tried it in a "real" terminal, or over SSH, you'd see it break.

    If you've only got one X server running, just specifying the display might work:

    * * * * *    DISPLAY=:0 firefox ...

    You could probably put more effort into working out what display it's sitting under rather than assuming it's :0 but that will probably work most of the time.

    If you just need to reload something a lot, look at Tab Auto Reload or similar Firefox plugins.