📌  相关文章
📜  python 每 5 分钟运行一次脚本 - Shell-Bash 代码示例

📅  最后修改于: 2022-03-11 14:51:42.757000             🧑  作者: Mango

代码示例1
# Credit: Jakub Jirutka
# I suppose that you have cron installed already; 
# if not, then install some (vixie-cron for an example).

# Create a new file /etc/cron.d/.cron with the following content:

# ---
# run script every 5 minutes
*/5 * * * *   myuser  python /path/to/script.py

# run script after system (re)boot
@reboot       myuser  python /path/to/script.py
# ---

# where myuser is the user to run the script 
# (it shouldn’t be root if possible, for security reasons). 
# If this doesn’t work, then try to append the content to /etc/crontab instead.

# You might want to redirect stdout/stderr of the script to file,
# so you can check if everything works fine. 
# This is same as in shell, 
# just add something like >>/var/log/-info.log 2>>/var/log/-error.log 
# after the script path.