我想在ubuntu16.04上使用crontab反复运行python脚本
我在终端上运行下面的命令。你知道吗
$crontab -e
并在上面写了如下。你知道吗
1 * * * * python /home/elite/python/weather.py
我认为,这确实意味着每分钟都要运行weather.py
脚本。你知道吗
这是用于测试crontab
功能的weather.py
脚本。你知道吗
from urllib import urlopen
import time
import re
testing = 'testing'
current_time = time.localtime()
today = time.strftime('%Y-%m-%-d-%-s', current_time)
file_name = today + ".txt"
output = open("/home/elite/python/" + file_name, "w")
output.write(testing)
当我在终端上运行这个脚本-$python weather.py
时,它运行得很好。你知道吗
但是crontab
似乎不起作用。你知道吗
我怎么处理?你知道吗
开头的1表示一小时中的一分钟,所以它应该每小时运行一次,而不是每分钟。你知道吗
如果你想每分钟都跑,你需要
* * * * *
两件事。你知道吗
首先,Crontab喜欢命令的绝对路径。例如
/usr/bin/python
。键入which python
以获取绝对路径。你知道吗其次,
1 * * * *
是每小时一次。我喜欢使用https://crontab.guru来帮助我的cron时间正确。你知道吗相关问题 更多 >
编程相关推荐