cron
jobs run in a completely separate environment, isolated from your usual GUI desktop or terminal environment.
firefox
expects to be run as a child process of your desktop environment or, at the very least to have a valid DISPLAY
variable set.
It is sometimes possible to get cron jobs to start or interact with GUI programs. Try adding export DISPLAY=:0.0
as the second line of your script. If :0.0
doesn't work, run a terminal in your desktop and run echo $DISPLAY
to get the correct value.
If this still doesn't work, you may also need to set XAUTHORITY=$HOME/.Xauthority
or maybe use xauth
to enable access.
Note that any program started from cron (including firefox) will inherit cron's fairly minimalist environment. Variables like PATH, LOGNAME and/or USER may be different to what you expect, and many variables won't be set at all. e.g. the LC_* locale variables may not be set (depending on distro - e.g. cron in Debian reads /etc/environment
and /etc/default/locale
. I don't know if that's also the case on Fedora or not). If that program needs specific environment variables set to certain values, you'll need to set them in your crontab file, or export
them in your script too. Or just source
your usual shell startup files from the script.
Firefox, Chromium, and other web browsers may need http_proxy
, https_proxy
and other proxy-related variables set.
FYI, this is roughly how running GUI programs over ssh -X
works. The -X
option enables X11 forwarding. It sets up a tunnel to proxy X protocol over the ssh connection, and sets the DISPLAY variable to point to that tunnel.
I use this to, for example, run xsane
on my server (hostname "ganesh", which has a HP3030 printer/scanner attached) but have the windows display on my workstation's monitor - i.e. ssh -X ganesh xsane
.
If I were to run ssh -X ganesh 'echo $DISPLAY'
(needs to be single-quoted or escaped so that my local shell doesn't interpolate the variable), I'd see something like:
$ ssh -X ganesh 'echo $DISPLAY'
ganesh:11.0