【问题标题】:Cannot get @reboot Cron job to run Python script无法获得@reboot Cron 作业来运行 Python 脚本
【发布时间】:2015-09-29 08:52:55
【问题描述】:

我有一个 cron 作业,它在重新启动时加载 Python 脚本,但它无法正常工作。 我已经检查了 Python 脚本,并且在 CLi 中运行良好。

.py 基本上将浏览器加载到 Google,然后将其发送到全屏。 (它实际上会加载另一个网站并输入登录详细信息,但出于明显的原因将其删除)

已经在这里待了好几个星期了,让我发疯,有什么想法吗?

运行 Raspbian 的树莓派。

  • $crontab -e

    @reboot DISPLAY=:0 python /prtgboot.py

  • prtgboot.py

'#'!/usr/bin/env python

import commands
import time

webbrowser = "iceweasel"
pgrepcmd = "pgrep %s " % (webbrowser)
process = commands.getoutput(pgrepcmd)

if process == "":
        from selenium import webdriver
        from selenium.webdriver.common.keys import Keys
        from selenium.webdriver import ActionChains
        browser = webdriver.Firefox() 
        actions = ActionChains(browser)
        browser.get('http://google.co.uk')
        elemFullscreen = browser.find_element_by_tag_name('html') 
        time.sleep(30)
        elemFullscreen.send_keys (Keys.F11) 
        exit()
else:
        exit()

【问题讨论】:

  • @reboot 存在 许多 问题,无法始终如一地工作 - 不适用于 root 等 - this summarizes a few discoveries
  • @Petesh - 我也试过添加到 /etc/xdg/lxsession/LXDE-pi/autostart 也没有运气。我现在将添加该文件,除了 Python 脚本之外,其他所有内容都可以正常工作。

标签: python linux cron iceweasel


【解决方案1】:

好的,Petesh 是对的。这是@reboot 无法正常工作。

将 cron 更改为 * * * * * 以便我的脚本每分钟运行一次。通常是不好的做法,但如果浏览器已经运行,则已经设置脚本结束。现在工作请客。

积极的一面是,如果浏览器崩溃,它会重新启动:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-06
    • 1970-01-01
    • 2013-03-16
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 2011-12-05
    相关资源
    最近更新 更多