如何设置 cron 作业以使用 crontab 在浏览器中打开网页?
我使用网站订餐,我希望该网站能够在每天上午 11 点在浏览器中自动打开。
我使用“crontab -e”打开 crontab 并尝试了这个:
59 10 1-31 1-12 SUN,MON,TUE,THU google-chrome --new-window http://food.com
还尝试了这个:
59 10 1-31 1-12 SUN,MON,TUE,THU x-www-browser http://food.com
但是他们给我发了一封电子邮件而不是打开网站:
(x-www-browser:16597): Gtk-WARNING **: cannot open display:
(google-chrome:16883): Gtk-WARNING **: cannot open display:
谢谢!
更新:解决方案是添加“export DISPLAY=:0 &&”到 crontab。 IE:
53 10 * 1-12 SUN,MON,TUE,THU export DISPLAY=:0 && google-chrome --new-window http://www.foodsite.com
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该错误意味着 GTK 无法找到 X 的运行位置。可能是您的 DISPLAY 变量未在 cron 尝试调用您的作业的上下文中设置。 请尝试添加
如果尚未设置 DISPLAY, 输入命令并查看打印出来的内容。
到您的 .bashrc 文件。要进行测试,请在终端中
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
To your .bashrc file if DISPLAY isn't set already. To test, enter the command
in a terminal and see what is printed out.