Python selenium脚本无法从crontab

时间:2017-07-18 10:14:46

标签: linux cron raspberry-pi xvfb

我想通过运行python selenium脚本在浏览器上打开一个网页,每n小时从crontab 运行。

它是一个非常标准的脚本,如果我在该机器上本地运行它。

因此,如果我将键盘连接到树莓上并运行

python /home/pi/ww/open_dashboard.py >> /home/pi/ww/selenium_output.txt

它将打开浏览器并执行我需要的selenium命令。

现在我也可以进入覆盆子并运行

export DISPLAY=:0 && python /home/pi/ww/open_dashboard.py >> /home/pi/ww/selenium_output.txt 

我可以看到浏览器打开并在连接到树莓的显示器上执行我需要的操作。

现在我将此行添加到cron。

57 9 * * * export DISPLAY=:0 && python /home/pi/ww/open_dashboard.py >> /home/pi/ww/selenium_output.txt

如果我检查grep CRON /var/log/syslog

,我可以看到cron执行了该命令
Jul 18 09:57:01 raspberrypi CRON[2971]: (pi) CMD (export DISPLAY=:0 && python /home/pi/ww/open_dashboard.py >> /home/pi/ww/selenium_output.txt)

但浏览器没有在连接到树莓的显示器上打开。我在这里做错了什么? :)

0 个答案:

没有答案