Python:subprocess在crontab中不起作用

时间:2018-06-18 12:12:02

标签: python python-2.7 cron subprocess lz4

extract.py

def extract_lz4(lz4_path):
    status = subprocess.call(["lz4", "-df", lz4_path], stderr=subprocess.STDOUT)
    log.info("In Extract fun STATUS : {}".format(status))
    if not status:
        log.info("Extract Successful of {}".format(lz4_path))
        return status
    else:
        log.info("Extract Successful of {}".format(lz4_path))
        return status

Main.py

 lz4_file = '<path-to-lz4-file>/ly486imc83e0v9a7-23-telnet-banner-full_ipv4-20180515T040003-zmap-results.csv.lz4'

 extract_status = extract_lz4_task(lz4_file)
 log.info("extract_status : {}".format(extract_status))

当我通过python <path-to-file>/main.py调用主文件时,它将成功提取。 但当我把它放在crontab中时它不会提取

crontab -e

* * * * * python <path-to-file>/main.py

我有什么遗失的吗?任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

尝试使用以下方法调试您的cron:

tail /var/log/cron

或添加日志文件

$ crontab -e
  * * * * * python <path-to-file>/main.py >> <path-to-file>/cron.log 2>&1