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?

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

  • Thanks! Actually, it's the same user, but I used the wrong display, it's 1, not 0. – Frank Steinmann Apr 29 '14 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
  • That didn't change anything. Still Error: cannot open display: :0. – Frank Steinmann Apr 28 '14 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.