当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 21 篇帖子 ]  前往页数 1, 2  下一页
作者 内容
1 楼 
 文章标题 : [wiki]CronHowto
帖子发表于 : 2005-07-22 14:14 
论坛管理员

注册: 2005-03-27 0:06
帖子: 10116
系统: Ubuntu 12.04
送出感谢: 7
接收感谢: 128
What is Cron?

Cron is a [daemon] used for scheduling tasks to be executed at a certain time. Each user has a crontab file, allowing them to specify actions and times that they should be executed. There is also a system crontab, allowing tasks such as log rotation and locate database updating to be done regularly.
Using Cron

To use cron, simply add entries to your crontab file. A crontab entry gives a patten specifying when to run and the action to perform, eg:

5 3 * * * /usr/bin/apt-get update

The first part of the crontab entry describes when the action will be performed. There are five fields, separated by whitespace, each of which accept a number, a star (*), or appropriate text. The fields specify, in order, the *minute*, *hour*, *day of month*, *month* and *day of week*. The month and day of week fields allow the use of an abbreviation, such as "jan" for January or "thu" for Thursday.

The example above will execute "/usr/bin/apt-get update" every day of every month at 03:05 (cron assumes 24 hour time). You could have cron annoy you every 5 minutes throughout your work day (9am-5pm) with a message:

*/5 9-17 * * mon,tue,wed,thur,fri wall "Are we there yet?"

or remind you of a birthday at 9 in the morning on the 10th January every year:

0 9 10 jan * echo "It's your mother's birthday today!" > ~/readme

To view the current contents of your crontab file, type:

crontab -l

To edit the file, with the editor specified in your environment (which defaults to vim - :q! is the command to escape without saving if you get stuck and need to read up on it or change your editor), use:

crontab -e

When you exit the editor, the new crontab file will be installed. The file is stored in /var/spool/cron/crontabs but should only be edited via the crontab command.
Further Considerations

The above commands are stored in a crontab file belonging to your user account and executed with your level of permissions. If you want to regularly run a command requiring a greater level of permissions, set up a root crontab file using:

sudo crontab -e

Depending on the commands being run, you may need to expand the root users PATH variable by putting the following line at the top of their crontab file:

PATH=/usr/sbin:/usr/bin:/sbin:/bin

It is sensible to test that your cron jobs work as intended. One method for doing this is to set up the job to run a couple of minutes in the future and then check the results before finalising the timing. You may also find it useful to put the commands into script files that log their success or failure, eg:

echo "Nightly Backup Successful: $(date)" >> /tmp/mybackup.log

For more information, see the man pages for cron and crontab (man is detailed on the BasicCommands page). If your machine is regularly switched off, you may also be interest in at (part of the Ubuntu base install) and anacron (found in the universe repository) that provide other approaches to scheduled tasks.

https://wiki.ubuntu.com/CronHowto


_________________
当净其意如虚空,远离妄想及诸取,令心所向皆无碍


页首
 用户资料  
 
2 楼 
 文章标题 :
帖子发表于 : 2005-07-23 11:09 
头像

注册: 2005-05-19 18:38
帖子: 1991
地址: 湖南永州
送出感谢: 0 次
接收感谢: 1
引用:
What is Cron?

Cron is a [daemon] used for scheduling tasks to be executed at a certain time. Each user has a crontab file, allowing them to specify actions and times that they should be executed. There is also a system crontab, allowing tasks such as log rotation and locate database updating to be done regularly.


什么是Cron

Cron是一个[守护程序]用于在指定的时间内执行行程类的任务,每一个用户都有一个 crontab 文件,来允许他们指定需要执行的内容和时间,此外,系统也有一个 crontab ,用来允许像交替日志和更新本地数据这样有规则的任务。


页首
 用户资料  
 
3 楼 
 文章标题 :
帖子发表于 : 2005-07-23 11:35 
头像

注册: 2005-05-19 18:38
帖子: 1991
地址: 湖南永州
送出感谢: 0 次
接收感谢: 1
引用:
Using Cron

To use cron, simply add entries to your crontab file. A crontab entry gives a patten specifying when to run and the action to perform, eg:

5 3 * * * /usr/bin/apt-get update


使用 Cron

使用 Cron, 只要在 crontab 文件中添加一些项目,一个 crontab 项目详细说明执行的过程和时间,如:

5 3 * * * /usr/bin/apt-get update


页首
 用户资料  
 
4 楼 
 文章标题 :
帖子发表于 : 2005-07-23 11:59 
头像

注册: 2005-05-19 18:38
帖子: 1991
地址: 湖南永州
送出感谢: 0 次
接收感谢: 1
引用:
The first part of the crontab entry describes when the action will be performed. There are five fields, separated by whitespace, each of which accept a number, a star (*), or appropriate text. The fields specify, in order, the *minute*, *hour*, *day of month*, *month* and *day of week*. The month and day of week fields allow the use of an abbreviation, such as "jan" for January or "thu" for Thursday.


在crontab 项目里的第一个部分描述了执行任务的时间。它用空格分开成五个区域,每个只能用数字、“*”、或适当的字。这个区域依次说明 “分”,“时”,“每月几日”、“月”、“每周星期几”,月和星期可以用缩写,如 “jan"代替“January" 、"thu" 代替"Thursday"。


页首
 用户资料  
 
5 楼 
 文章标题 :
帖子发表于 : 2005-07-23 12:01 
头像

注册: 2005-05-19 18:38
帖子: 1991
地址: 湖南永州
送出感谢: 0 次
接收感谢: 1
引用:
The example above will execute "/usr/bin/apt-get update" every day of every month at 03:05 (cron assumes 24 hour time).


上面的例子将在每天的03:05执行“/usr/bin/apt-get update”(cron采用24小时制)


页首
 用户资料  
 
6 楼 
 文章标题 :
帖子发表于 : 2005-07-24 10:04 
头像

注册: 2005-05-19 18:38
帖子: 1991
地址: 湖南永州
送出感谢: 0 次
接收感谢: 1
引用:
You could have cron you every 5 minutes throughout your work day (9am-5pm) with a message:

*/5 9-17 * * mon,tue,wed,thur,fri wall "Are we there yet?"


你要让cron在所有工作日中每5分钟显示干扰的消息,(上午9点到下午5点)请用

*/5 9-17 * * mon,tue,wed,thur,fri wall "我们在不在?"


最后由 gnix_oag 编辑于 2005-07-24 10:18,总共编辑了 2 次

页首
 用户资料  
 
7 楼 
 文章标题 :
帖子发表于 : 2005-07-24 10:11 
头像

注册: 2005-05-19 18:38
帖子: 1991
地址: 湖南永州
送出感谢: 0 次
接收感谢: 1
引用:
or remind you of a birthday at 9 in the morning on the 10th January every year:

0 9 10 jan * echo "It's your mother's birthday today!" > ~/readme


或者想使你想起一个生日,在每年正月十日的上午9点,用:

0 9 10 jan * echo "今天是妈妈的生日" > ~/readme


最后由 gnix_oag 编辑于 2005-07-24 10:17,总共编辑了 1 次

页首
 用户资料  
 
8 楼 
 文章标题 :
帖子发表于 : 2005-07-24 10:16 
头像

注册: 2005-05-19 18:38
帖子: 1991
地址: 湖南永州
送出感谢: 0 次
接收感谢: 1
引用:
To view the current contents of your crontab file, type:

crontab -l


查看 crontab 文件当今的内容,输入:

crontab -l


页首
 用户资料  
 
9 楼 
 文章标题 :
帖子发表于 : 2005-07-24 10:24 
头像

注册: 2005-05-19 18:38
帖子: 1991
地址: 湖南永州
送出感谢: 0 次
接收感谢: 1
引用:
To edit the file, with the editor specified in your environment (which defaults to vim - :q! is the command to escape without saving if you get stuck and need to read up on it or change your editor), use:

crontab -e


用环境变量指定的编辑器编辑这个文件(),用

crontab -e


页首
 用户资料  
 
10 楼 
 文章标题 :
帖子发表于 : 2005-07-24 10:45 
头像

注册: 2005-05-19 18:38
帖子: 1991
地址: 湖南永州
送出感谢: 0 次
接收感谢: 1
引用:
When you exit the editor, the new crontab file will be installed. The file is stored in /var/spool/cron/crontabs but should only be edited via the crontab command.


当你关闭编辑器后,新的 crontab 文件将被安装上。用 crontab 命令编辑的文件保存在/var/spool/cron/crontabs


页首
 用户资料  
 
11 楼 
 文章标题 :
帖子发表于 : 2005-07-24 10:46 
头像

注册: 2005-05-19 18:38
帖子: 1991
地址: 湖南永州
送出感谢: 0 次
接收感谢: 1
引用:
Further Considerations

The above commands are stored in a crontab file belonging to your user account and with your level of permissions. If you want to regularly run a command requiring a greater level of permissions, set up a root crontab file using:

sudo crontab -e


更多的内容

下面的命令保存 crontab 文件需要你的用户有要许可。如果你想要定期运行更大权限的命令, 请设置根 crontab 文件:

sudo crontab -e


页首
 用户资料  
 
12 楼 
 文章标题 :
帖子发表于 : 2005-07-24 11:10 
头像

注册: 2005-05-19 18:38
帖子: 1991
地址: 湖南永州
送出感谢: 0 次
接收感谢: 1
引用:
Depending on the commands being run, you may need to expand the root users PATH variable by putting the following line at the top of their crontab file:

PATH=/usr/sbin:/usr/bin:/sbin:/bin


依靠命令才能运行的,你可能需要扩大根用户的 PATH 变量,请在他们的 crontab 文件的顶部输入下面的内容:

PATH=/usr/sbin:/usr/bin:/sbin:/bin


页首
 用户资料  
 
13 楼 
 文章标题 :
帖子发表于 : 2005-07-24 11:12 
头像

注册: 2005-05-19 18:38
帖子: 1991
地址: 湖南永州
送出感谢: 0 次
接收感谢: 1
引用:
It is sensible to test that your cron jobs work as intended. One method for doing this is to set up the job to run a couple of minutes in the future and then check the results before finalising the timing. You may also find it useful to put the commands into script files that log their success or failure, eg:

echo "Nightly Backup Successful: $(date)" >> /tmp/mybackup.log


页首
 用户资料  
 
14 楼 
 文章标题 :
帖子发表于 : 2005-07-27 19:09 
头像

注册: 2005-05-19 18:38
帖子: 1991
地址: 湖南永州
送出感谢: 0 次
接收感谢: 1
水平有限,我还不如从书上抄一段呢,书上多的是,


页首
 用户资料  
 
15 楼 
 文章标题 :
帖子发表于 : 2005-08-22 21:38 
论坛管理员

注册: 2005-03-27 0:06
帖子: 10116
系统: Ubuntu 12.04
送出感谢: 7
接收感谢: 128
谁接下去翻译完?


_________________
当净其意如虚空,远离妄想及诸取,令心所向皆无碍


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 21 篇帖子 ]  前往页数 1, 2  下一页

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 3 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译