I have gone through many answers as to how to add a crontab through terminal through one liners and came across only one single option everywhere which is

{crontab -l; echo "1 * * * * /usr/bin/firefox" } | crontab -

Running which all I am receiving is


That's it. A promt for me to type something.

and second option being

(crontab -l; echo "1 * * * * /usr/bin/firefox" ) | crontab -

Which seems to add the cron to /var/spool/cron/crontabs/root but does not open firefox every minute, in fact it does not open at all.

I read most on most answers that you should not edit the /var/spool/cron/crontabs/root or /etc/crontab files directly.

Is this not supported in my system or what?

An output of uname -a gave the following description of my system

Linux earth 4.9.0-kali4-amd64 #1 SMP Debian 4.9.30-2kali1 (2017-06-22) x86_64 GNU/Linux

EDIT: Following message logs are repeated often in my /var/spool/mail/mail logs

From root@localhost.localdomain Sun Jul 09 16:01:12 2017 
Return-path: < root@localhost.localdomain > 
Envelope-to: root@localhost.localdomain 
Delivery-date: Sun, 09 Jul 2017 16:01:12 +0530 
Received: from root by earth with local (Exim 4.89)   
    (envelope-from <root@localhost.localdomain>)  
    id 1dU9UY-0001Ry-3A   
    for root@localhost.localdomain; Sun, 09 Jul 2017 16:01:06 +0530 
From: root@localhost.localdomain (Cron Daemon) 
To: root@localhost.localdomain 
Subject: Cron <root@earth> /usr/bin/firefox 
MIME-Version: 1.0 
Content-Type: text/plain; charset=UTF-8 
Content-Transfer-Encoding: 8bit X-Cron-Env: < SHELL=/bin/sh > 
X-Cron-Env: < HOME=/root > 
X-Cron-Env: < PATH=/usr/bin:/bin > 
X-Cron-Env: < LOGNAME=root > Message-Id: < E1dU9UY-0001Ry-3A@earth > 
Date: Sun, 09 Jul 2017 16:01:06 +0530

Error: GDK_BACKEND does not match available displays

2 Answers 2


Most likely your second attempt is correct, but your expectation is wrong.

Let's look at it in parts:

crontab -l

lists all existing entries for the current user's crontab. The

echo "1 * * * * /usr/bin/firefox"

just prints that line again. These two commands are then grouped together in a subshell and the common output is piped into

crontab -

So the crontab is overwritten by what comes in via the standard input, which in this case is the old crontab plus the new entry.

As you said it is added to the crontab file. And, assuming the cron daemon is running, the command will be executed each minute.

So why aren't you seeing a firefox window each minute? - Because the conrjob runs in a different shell below the cron daemon, which doesn't have access to your X session, thus firefox will fail and report something like

(firefox:22376): Gtk-WARNING **: Locale not supported by C library.
    Using the fallback 'C' locale.
Error: GDK_BACKEND does not match available displays

And terminate. How to see that error? Typically the cron daemon will try to send you a mail, see /var/spool/mail eventually.

About the two forms:

{ crontab -l; echo "1 * * * * /usr/bin/firefox" } | crontab -

would have to be written as

{ crontab -l; echo "1 * * * * /usr/bin/firefox"; } | crontab -

(mind the extra semicolon)

The difference between () and {} is that the former creates a sub-shell, whereas the later executes the commands in the same shell context. Thus variable assignments survive in one form, not in the other.

  • I don't know, it adds 1 * * * * /usr/bin/firefox to /var/spool/cron/crontab/root but it just doesn't start firefox. Had a look on service cron status. it is running too. It does not add this to /etc/crontab although, if that is important. Jul 8, 2017 at 22:05
  • I'm quite sure it starts firefox, but firefox doesn't find a display it can use. Check your logs and mail (i.e. in /var/spool/mail)
    – johannes
    Jul 9, 2017 at 11:05
  • yes there is an error Error: GDK_BACKEND does not match available displays repeated so many times in my logs, check the question above, I have updated it with the error. What do I do? Jul 9, 2017 at 11:32
  • What's your actual goal? Adding cron entries works.
    – johannes
    Jul 9, 2017 at 11:57
  • I have my large data uploaded to mega.nz website which requires users to open its website at least once in 2 months or else they'd assume the account inactive and delete the data. So, I want Firefox to open mega.nz once every 2 weeks (in order to be on safe side). So can cron have access to X by any chance? If not, how can I achieve this? Jul 9, 2017 at 14:50

I was getting the same error when trying to have firefox-esr launched from a cron job.

Setting DISPLAY right inside the cron file has helped though:

* * * * * pi export DISPLAY=:0 && /usr/bin/firefox-esr &

(Make sure to figure out your actual DISPLAY number by doing echo $DISPLAY)

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.