Ani*_*oud 23 browser cron google-chrome crontab
我使用网站订购食物,我希望这个网站在上午11点在浏览器中自动打开.
我使用"crontab -e"打开了crontab并尝试了这个:
59 10 1-31 1-12 SUN,MON,TUE,THU google-chrome --new-window http://food.com
Run Code Online (Sandbox Code Playgroud)
并试过这个:
59 10 1-31 1-12 SUN,MON,TUE,THU x-www-browser http://food.com
Run Code Online (Sandbox Code Playgroud)
但他们给我发了一封电子邮件,而不是打开网站:
(x-www-browser:16597): Gtk-WARNING **: cannot open display:
(google-chrome:16883): Gtk-WARNING **: cannot open display:
Run Code Online (Sandbox Code Playgroud)
谢谢!
更新:解决方案是将"export DISPLAY =:0 &&"添加到crontab.即:
53 10 * 1-12 SUN,MON,TUE,THU export DISPLAY=:0 && google-chrome --new-window http://www.foodsite.com
Run Code Online (Sandbox Code Playgroud)
Jos*_*son 20
该错误意味着GTK无法找到X正在运行的位置.可能是您的DISPLAY变量未在cron尝试调用您的作业的上下文中设置.尝试添加
export DISPLAY=:0
Run Code Online (Sandbox Code Playgroud)
如果尚未设置DISPLAY,则转到.bashrc文件.要进行测试,请输入命令
echo $DISPLAY
Run Code Online (Sandbox Code Playgroud)
在一个终端,看看打印出来的是什么.