1

I want to write a crontab that opens Firefox every minute (just to test it, I know it doesn't make any sense). My problem is that even though crontab is active nothing happens. This is how my crontab looks like:

SHELL=/bin/bash
PATH=~/bin:/usr/bin:bin
* * * * * export DISPLAY=:0.0 xhost localuser /usr/bin/firefox

Any idea why it isn't working?

2
  • Is there any error in the cron's log file ?
    – Vinz
    Commented Nov 5, 2015 at 11:51
  • 2
    This link serverfault.com/questions/449651/… will likely help you solve your problem. If it does not it will help you gather information that will help us help you. You should edit that information into your question. Note too that in general SF does not accept workstation questions.
    – user591
    Commented Nov 5, 2015 at 11:57

1 Answer 1

3
export DISPLAY=:0.0 xhost localuser /usr/bin/firefox

Just from looking at the above cron command, I can see why it won’t work. The usage for the export command is

export name[=word]...

In POSIX shells, the rest of the words following export DISPLAY=:0.0 will be treated as other shell variables that should be exported to the environment – not commands that will be run. POSIX (Issue 7, 2018 edition) also specifies that a name should be

a word consisting solely of underscores, digits, and alphabetics from the portable character set.

This means that shell variable names can not contain characters such as / so attempting to include /usr/bin/firefox among the list of variable names to be exported would throw an error with a message such as not a valid identifier or bad variable name.


Also, the xhost command is used incorrectly. Run xhost by itself to see if you need to add your user account as an allowed user. This should only need to be run once and shouldn’t be scheduled by cron.


Unless there’s some other mechanism preventing programs from connecting to the X display server, the above lines can simply be replaced with:

DISPLAY=:0.0
* * * * * /usr/bin/firefox

This should launch a new Firefox window every minute. There’s also no need to specify the SHELL environment variable – and since you’re specifying the full path for the firefox executable, there’s no need to set the PATH variable either.


See also: POSIX specification for export

0

You must log in to answer this question.

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