0

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:

#!/bin/bash

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 Answers2

0

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.

dobey
  • 41,650
-1

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