[英]How to run a python script with CRON on Debian?
我想每隔X個小時運行一個腳本,這就是為什么我寫了一個BASH(名為mybash.sh)的原因,該腳本像這樣調用該腳本:
#!/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/usr/src/Python-2.7.13 python /usr/src/Python-2.7.13/test1.py
這個bash文件在我的/usr/src/Python-2.7.13和我的test1.py中。 如果我正在運行sh mybash.sh
它正在運行! 我也做了chmod a+x mybash
。
我在crontab-e
寫道:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/usr/src/Python-2.7.13
* * * * * /usr/src/Python-2.7.13/mybash.sh 2>&1
如果我打電話給crontab-l
我在那看到這些行。
但是我的腳本沒有運行。.我錯過了什么?
EDIT1-貓/ etc / crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
您可以在crontab中簡單地調用python
* * * * * [path/to/py/executable] [path/to/py/script]
由於cron環境中的變量受限,請記住指定可執行文件的完整路徑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.