google-chromebrowsercron

How to set a cron job to open a web page in the browser using crontab?


I use a website to order food, and I would like this website to be automatically opened in the browser at 11 am day.

I opened crontab using "crontab -e" and tried this:

59 10 1-31 1-12 SUN,MON,TUE,THU google-chrome --new-window http://food.com

and also tried this:

59 10 1-31 1-12 SUN,MON,TUE,THU x-www-browser http://food.com

But they sent me an email instead of opening the website:

(x-www-browser:16597): Gtk-WARNING **: cannot open display:
(google-chrome:16883): Gtk-WARNING **: cannot open display:

Thanks!


Update: The solution was adding "export DISPLAY=:0 &&" to crontab. i.e.:

53 10 * 1-12 SUN,MON,TUE,THU export DISPLAY=:0 && google-chrome --new-window http://www.foodsite.com

Solution

  • That error means that GTK cannot find where X is running. It might be your DISPLAY variable is not set in the context that cron is trying to call your job. Try adding

    export DISPLAY=:0
    

    To your .bashrc file if DISPLAY isn't set already. To test, enter the command

    echo $DISPLAY
    

    in a terminal and see what is printed out.