前提:
#!/usr/bin/python3
# -*- conding= utf-8 -*-
print('hello world')
chmod 777 xxx.py
这样python文件就可以执行了
ubuntu@VM-0-10-ubuntu:~/script$ ./test.py
hello world
crontab -e
第一次执行会让用户选择编辑器,自己根据喜好选择编辑器
进入编辑会显示如下代码: 1 # Edit this file to introduce tasks to be run by cron.
2 #
3 # Each task to run has to be defined through a single line
4 # indicating with different fields when the task will be run
5 # and what command to run for the task
6 #
7 # To define the time you can provide concrete values for
8 # minute (m), hour (h), day of month (dom), month (mon),
9 # and day of week (dow) or use '*' in these fields (for 'any').#
10 # Notice that tasks will be started based on the cron's system
11 # daemon's notion of time and timezones.
12 #
13 # Output of the crontab jobs (including errors) is sent through
14 # email to the user the crontab file belongs to (unless redirected).
15 #
16 # For example, you can run a backup of all your user accounts
17 # at 5 a.m every week with:
18 # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
19 #
20 # For more information see the manual pages of crontab(5) and cron(8)
21 #
22 # m h dom mon dow command
23 #* * * * * /home/ubuntu/python/Simple_review_system/component/emailer.sh >> /home/ubuntu/script/review_emailer.log 2 >&1
~
crontab -l
crontab -e
:进入crontab编辑模式{minute} {hour} {day-of-month} {month} {day-of-week} {full-path-to-shell-script} ( >> {full-path-to/xxx.log 2>&1})
(括号里面可选项,添加日志)示例:
0 2 * * * /path/xxx.py
0 5,17 * * * /path/xxx.py
* * * * * /path/xxx.py
0 17 * * sun /path/xxx.py
*/10 * * * * /path/xxx.py
* * *jan,may,aug * /path/xxx.py
* * * * * /path/xxx.py
* * * * * sleep 30; /path/xxx.py
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/172606.html原文链接:https://javaforall.cn