linux计划任务

crontab -r #删除所有任务
crontab -l #列出当前的定时任务
crontab -e #编辑crontab内容

第一次使用如果出现如下提示,是选择编辑器

1
2
3
4
5
6
7
8
liuyx@myubuntu:/$ crontab -e
no crontab for liuyx - using an empty one

Select an editor. To change later, run 'select-editor'.
1. /bin/ed
2. /bin/nano <---- easiest
3. /usr/bin/vim.basic
4. /usr/bin/vim.tiny

选择vim编辑器

1
2
Choose 1-3 [2]: 3
crontab: installing new crontab

重新选择编辑器
select-editor

执行crontab -e

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
* * * * * /home/xxxx.sh
1
2
ubuntu 系统下用 sudo service cron restart
redhat 系统下用 sudo service crond restart

redhat查看日志

1
tail -f /var/log/cron

Ubuntu 需要手动开启 Crontab 计划任务日志
参考 https://www.cnblogs.com/dee0912/p/4479196.html

文章作者: 柯熠
文章链接: https://smallkserver.github.io/2019/10/29/linux创建计划任务/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Smallkserver
打赏
  • 微信
  • 支付宝

评论