I made a simple "journal" program that will open a GUI, prompt for an entry and a few factors, and print this information to a file under the current date. I've written a short bit of java code that does this when run, and I want to use cron to schedule it to run every day.

I also wrote a small script ("javashell.sh") to change to the directory where I have the java code, compile it, and run the java program. Its contents are this:


cd /home/otolithic/Desktop/projects;
javac Journal.java;
java Journal;

(Its so short as to feel pointless but I thought it would be necessary to easily run the program from cron; I'm totally new to Linux so let me know if this is weird or not)

I put it in usr/local/bin so I can just type "javashell.sh" in the terminal and the journal app runs no problem. But when I try to make a cronjob out of this command, I can see in the logs that it's run but no GUI ever pops up to ask for a journal entry like it does when I just run javashell.sh outside of cron.

I've tried (after the minute/hour/etc.):

export DISPLAY=:0 && javashell.sh
DISPLAY=:0 javashell.sh
env DISPLAY=:0 javashell.sh
$DISPLAY=:0 && javashell.sh
cd ~/path/to/file && javac Journal.java && java Journal
env DISPLAY=:0 && cd ~/path/to/file && javac Journal.java && java Journal

to no effect.

I checked that my display is in fact :0 so the problem isn't that. So why isn't this working?

Edit: also tried env DISPLAY=:0 && cd /home/otolithic/Desktop/projects && javac Journal.java && java Journal


2 Answers 2


You cannot open a program on your display from cron. Any job you wish to run via cron must not require any services of a logged in user session, including a valid display to place GUI apps on.

  • Oh, ok. I've seen other people ask about running stuff with a GUI with cron though (e.g. an internet radio player, a webpage), with the general solution being to set DISPLAY=:0 in the job. What's the difference here?
    – otolithic
    Jun 4, 2016 at 2:40
  • I can't answer why it doesn't work exactly. You should have an e-mail in /var/spool/mail/ in the file for your user, explaining any failures. I don't know what your code is doing exactly. For all I know, it's not even trying to connect to a display. But generally, anything that requires a user session shouldn't be done via cron.
    – dobey
    Jun 4, 2016 at 2:53

The crontab may use a different user than you. When you say

 cd ~/path/to/file

you are directing the file from your own user directory by using ~. You should use the absolute path which is in your case:

cd /home/yourusername/path/to/file

  • I gave that a try, but it's not working either. Thank you though, I didn't know that before and I had used ~ in javashell.sh as well and changed it there too just in case.
    – otolithic
    Jun 4, 2016 at 1:10
  • Sorry to hear that it did not work. Maybe someone else will be more helpful if you put what you have inside your javashell.sh. If your crontab is running javashell but nothing happens, it is possible that your javashell has a problem. Jun 4, 2016 at 1:16
  • This is a comment, not an answer.
    – dobey
    Jun 4, 2016 at 2:21

You must log in to answer this question.

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