2

I put this line in the crontab:

1 * * * * DISPLAY=:0.0 /usr/bin/gnome-terminal -e /home/user/Desktop/mltpl

The script is executable.

If paste that command in the terminal--that is, the string without stars, it works perfectly:

DISPLAY=:0.0 /usr/bin/gnome-terminal -e /home/user/Desktop/mltpl

I tried:

sudo service cron restart

But the problem persists. How can I get cron to run that command hourly?


Update. Got it working with ROOT crontab:

1 * * * * DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1000 XAUTHORITY=/home/user/.Xauthority /usr/bin/gnome-terminal -e /home/user/Desktop/mltpl
ngc3o34
  • 65

1 Answers1

5

I guess my first guess about the way the DISPLAY variable is handled is wrong. I think the problem somehow related to cron using a non-interactive shell. A test script using an infinite read loop failed to run. However, when I tested by opening a new tab:

* * * * * DISPLAY=:0 /usr/bin/gnome-terminal --tab -e /home/murukesh/test.sh

it worked fine.


According to this SU question and this Ubuntu Forums post, you may have to either export the $DISPLAY variable or use env:

1 * * * * env DISPLAY=:0.0 /usr/bin/gnome-terminal -e /home/user/Desktop/mltpl

(or)

1 * * * * export DISPLAY=:0.0 && /usr/bin/gnome-terminal -e /home/user/Desktop/mltpl

This maybe due to the shell used by cron being sh and not bash (see What's the difference between set, export and env and when should I use each?). Also have a look at Script doesn't run via crontab but works fine standalone.

muru
  • 207,228