Tuesday, May 14, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 2087  / 1 Year ago, sat, may 6, 2023, 8:48:44

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?


More From » command-line

 Answers
2

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


[#25586] Monday, May 8, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ibuteking

Total Points: 35
Total Questions: 128
Total Answers: 138

Location: Indonesia
Member since Thu, Oct 1, 2020
4 Years ago
;