1

I have a Ubuntu 14.04 system that just runs Firefox all day. Now I want to restart Firefox automatically once a day, so I created the following shell script:

#!/bin/sh
killall firefox
sleep 5
killall -9 firefox
sleep 2
/usr/bin/firefox -URL <...>

and set up da cronjob to call the script. But it doesn't work, I get:

Error: no display specified

When I insert

export DISPLAY=:0

I get

No protocol specified
No protocol specified
Error: cannot open display: :0

What's the correct way to do it?

2 Answers 2

1

To execute a command through xserver of another user need to export two variables:
XAUTHORITY and DISPLAY.

First of all, is what DISPLAY is connected to the user by typing:

w

assuming that the user "username" uses the display "1", and that the script should be run at 23:30, upgrade your crontab, as follows:

30 23 *** export XAUTHORITY=/home/username/.Xauthority && export DISPLAY=:1 && /path/to/script 2> /tmp/error_cron.log 

the last part of the line is to save any errors in /tmp/error_cron.log

1
  • Thanks! Actually, it's the same user, but I used the wrong display, it's 1, not 0. Apr 29, 2014 at 6:41
0

First be sure to edit the crontab with crontab -e and not one of the files under /etc (like /etc/cron.hourly).

Then you need to declare the DISPLAY variable in the cronjob itself:

DISPLAY=:0 /path/to/your/script
1
  • That didn't change anything. Still Error: cannot open display: :0. Apr 28, 2014 at 16:14

You must log in to answer this question.

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