我有一个 script.py 调用其他多处理脚本,如下所示 scripts.py:
import os
from multiprocessing import Pool
scriptspy = [
'/pyscripts/apoiont01.py',
'/pyscripts/access.py',
'/pyscripts/dental.py',
'/pyscripts/cremers.py',
'/pyscripts/delcuritib.py',
'/pyscripts/dtalndes.py',
'/pyscripts/lobo.py',
'/pyscripts/ierre.py',
'/pyscripts/daster.py',
'/pyscripts/dsul.py',
'/pyscripts/doema.py',
'/pyscripts/maz.py',
'/pyscripts/deura.py',
'/pyscripts/der.py',
'/pyscripts/dlo.py',
'/pyscripts/deoltda.py',
'/pyscripts/dpeed.py',
'/pyscripts/derr.py',
'/pyscripts/dweb.py',
]
def roda_processo(processo):
os.system('python3.7 {}'.format(processo))
for s in scriptspy:
roda_processo(s)
我的 crontab -e:
* * * * 1,5 /usr/local/bin/python3.7 /pyscripts/scripts.py > /pyscripts/logs/scripts.log
有趣的是,如果我在终端上运行相同的手动运行命令:/ usr / local / bin / python3. 7 /pyscripts/scripts.py > / pyscripts/logs / scripts.log
它正常运行。
log/var/log/cron.log: https://gist.githubusercontent.com/braganetx/a05c8b7257df79305dd1b79008323011/raw/8aec453a74566e8872608d1705f05004c1e12e5e/log
您应该将其替换为具有 python 解释器完整路径的版本,因为从cron
运行的任何内容都缺少"通常"的环境变量设置,即 PATH 是您最缺少的:
def roda_processo(processo):
os.system('/usr/local/bin/python3.7 {}'.format(processo))