【发布时间】:2018-09-12 04:05:24
【问题描述】:
我在 Ubuntu Server 16.04 上运行 Python 3.7,我有一个非常基本的 Python 脚本,可以从命令行正常运行,它通过简单的 shell 脚本运行良好,当我通过 crontab -e 设置 cron 作业时,或 webmin,cron 作业将在日志中显示为已发生。但是,该脚本实际上并没有运行,因为我将它设置为记录自身,并且它什么也不记录。谁能告诉我我在这里缺少什么?
我的 shell 脚本(getprice.sh):
#!/bin/sh
python3.7 /home/websites/www.coin-stack.com/py/getprice.py
我的python代码(getprice.py):
#!/usr/bin python3.7
import requests
import json
import logging
# ******************************* Settings *****************************************************************************
# Logging Setup
debug_level = 'INFO'
logging.basicConfig(level=logging.INFO, filename='run.log', format=' %(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
crawl_queue = []
delay = 60
url = 'http://www.somedomainoranother.com/?p=somepage'
# **********************************************************************************************************************
def main():
data = get_prices(url)
data = json.loads(data)
# Bitcoin
btc = data['BTC']
btc = btc['USD']
return btc
def get_prices(url):
resp = requests.get(url=url)
data = resp.content
return data
main()
我的 cron 工作:
*/10 * * * * /home/websites/www.mydomain.com/py/getprice.sh
【问题讨论】: