Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 511
Anis Abboud Avatar asked Sep 09 '25 21:09

Anis Abboud


1 Answers

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.

like image 123
Joshua Hutchison Avatar answered Sep 13 '25 06:09

Joshua Hutchison



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!