手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆

翻译:crontab的介绍

首页 > Linux >

以下内容来自于linux的101个hack,昨天看到了,顺手翻译了一下,毕竟看中文比看英文舒服。翻译的还是有点问题的,理解一下下啦。。。

Hack 74. Crontab
第74个hack:Crontab

Using cron you can execute a shell-script or Linux commands at a specific time and date. For example a sysadmin can schedule a backup job that can run every day. 
使用cron功能你可以在任意的时间执行一条shell指令或者Linux的命令。例如系统管理员可以运行一个计划任务来进行每天的备份工作。

How to add a job to the cron?
那么,怎么样把一个任务加入到cron呢?

# crontab –e
0 5 * * * /root/bin/backup.sh

This will execute /root/bin/backup.sh at 5 a.m every day.
上面这条指令,让你在每天上午5点 运行 /root/bin/目录下的 backup.sh 指令

Description of Cron fields.
Cron命令的各个字段的注释。

Following is the format of the crontab file.
crontab文件的格式均以下格式 

{minute} {hour} {day-of-month} {month} {day-of-week} {full-path-to-shell-script}
{分钟} {小时} {每月的第几天} {月份} {每周的第几天} {指令的全路径}
 
o  minute: Allowed range 0 -59
o  分钟的取值范围是 0-59

o  hour: Allowed range 0 -23
o  小时的取值范围是 0-23

o  day-of-month: Allowed range 0 - 31
o  每月的第几天,取值范围为 0-31

o  month: Allowed range 1 -12.  1 = January. 12 = December.
o  月份的取值范围为 1-12 ,1是1月,12是12月

o  Day-of-week: Allowed range 0 -7. Sunday is either 0 or 7.
o  每周的第几天,取值范围为0-7,0或者7都代表星期天
 
Crontab examples
Crontab 的例子

1. Run at 12:01 a.m. 1 minute after midnight everyday. This is a good time to run backup when the system is not under load. 
1. 每天午夜12点零1分 ,当系统不再被加载时就是进行备份的好时机(not under load翻译不来)
 
1 0 * * * /root/bin/backup.sh
 

2.  Run backup every weekday (Mon – Fri) at 11:59 p.m. 
每周1-5晚上11点59分执行备份操作

59 11 * * 1,2,3,4,5 /root/bin/backup.sh
 
Following will also do the same.
下面的例子则是另一种格式,功能完全一致

59 11 * * 1-5 /root/bin/backup.sh

3. Execute the command every 5 minutes.
 每五分钟执行一条命令
*/5 * * * * /root/bin/check-status.sh
 
4. Execute at 1:10 p.m on 1st of every month
 每月第一天的下午1点10分执行备份
10 13 1 * * /root/bin/full-backup.sh
 
5. Execute 11 p.m on weekdays.
每周工作日的下午11点执行备份
0 23 * * 1-5 /root/bin/incremental-backup.sh
 
Crontab Options
Crontab 的一些参数

Following are the available options with crontab:
以下是crontab所支持一些参数

o  crontab –e : Edit the crontab file. This will create a crontab, if it doesn’t exist
o  crontab -e : 编辑crontab文件,如果文件不存在,则创建一个crontab

o  crontab –l : Display the crontab file.
o  crontab -l : 显示crontab文件

o  crontab -r : Remove the crontab file.
o  crontab -r : 删除crontab文件

o  crontab -ir : This will prompt user before deleting a crontab. 
o  crontag -ir : 删除crontab文件,但在删除前会让用户进行确认




本站采用创作共享版权协议, 要求署名、非商业和保持一致. 本站欢迎任何非商业应用的转载, 但须注明出自"易栈网-膘叔", 保留原始链接, 此外还必须标注原文标题和链接.

Tags: crontab

« 上一篇 | 下一篇 »

只显示10条记录相关文章

让CRONTAB精确到秒的执行任务 (浏览: 23390, 评论: 0)
动态添加和删除crontab (浏览: 16205, 评论: 0)
crontab 式的多线程 (浏览: 14432, 评论: 0)

发表评论

评论内容 (必填):