Apart from video games one of the great advantages of using computers is that they don’t seem to mind doing boring and repetitive tasks that we would rather not do.除了视频游戏的一大优点是使用电脑,他们看起来并不介意做枯燥,重复的任务,我们不愿意这样做。 For monotonous tasks such as running daily backups we are better off scheduling them to run at a certain time every day, and do more interesting stuff with our time.对于单调的任务,如每天备份运行,我们会更好调度运行它们在一定的时间,每天和做更多有趣的东西与我们的时间。 Linux and UNIX usually come with the utility “crontab” by default. Linux和UNIX通常与实用“ crontab ”的默认。 This very useful command allows you to schedule tasks to run at a specified time and repeat as configured.这非常有用的命令可以让你的时间表运行的任务在指定时间和重复配置。 A task scheduled using “crontab” is called a “cron job”.一个工作计划使用“ crontab ”是所谓的“作业” 。
The crontab command allows you to instruct your server to execute a script at a specified minute of the specified day of the particular month.在crontab命令允许你指示您的服务器来执行一个脚本在指定分钟指定的一天,尤其是一个月。 To see what cron jobs are setup to run on your machine, run the following command:看看玉米职位设置运行在你的机器上,运行下面的命令:
# crontab -l # crontab - 1
If your machine has some cron jobs configured it will display something like the following:如果你的机器有一些玉米工作岗位配置它会显示类似如下:
0 6 * * * /opt/scripts/backup_script.sh 0 6 * * * /选择/脚本/ backup_script.sh
The crontab configuration above shows a cron job that executes the shell script “backup_script” everyday at 6 AM. crontab配置的上述表明,作业的执行的shell脚本“ backup_script ”每天早上6点。 The * means to run at every instance of the value in the field. *手段的运行在每一个个体的价值在外地。 So an asterisk in the day, month, and day of week fields in the above example means that the script should run every day of the month, every month of the year, and every day of the week.因此,一个星号在一天,一个月,一周内每天的领域上面的例子就是说,脚本应每天每月,每一个月的一年,每一天的一周。 The first and second fields tell crontab to execute the script at zero minutes and six hours, which is 6 AM.第一届和第二届领域告诉crontab来执行脚本零分钟, 6个小时,这是6月21日上午。 So, this cron job configuration would read something like this, “Run the script /opt/scripts/backup_script.sh at zero minutes, 6 AM, every day, every month, and every day of the week.” Below is the “anatomy” of a crontab configuration explained.因此,本计划作业配置如下这样的事情, “运行脚本/选择/脚本/ backup_script.sh零分钟,早晨6点,每一天,每一个月,每一天的一周。 ”下面是“解剖“一个crontab配置解释。
0 6 * * * /opt/scripts/backup_script.sh 0 6 * * * /选择/脚本/ backup_script.sh
| | | | | | | | | |
| | | | |________________ day of week (Sunday=0) | | | | |________________星期(星期日= 0 )
| | | |__________________ month of year | | | |__________________一个月一年
| | |____________________ day of month | | |____________________一天一个月
| |______________________ hour of day | |______________________小时的一天
|________________________ minute of hour |________________________分钟小时
To schedule new cron jobs or to edit old ones execute the following command:要安排就业的新玉米或修改旧的执行下面的命令:
# crontab -e # crontab娥
This will bring up an editor with which you can add, edit, or delete “cron jobs”.这将使一个编辑器,你可以添加,修改或删除“玉米就业” 。 To schedule a job to run at 3:45 PM every Monday add entry like this:要安排工作运行下午3点45分每星期一新增条目这样的:
45 15 * * 1 /opt/scripts/script.sh 45 15 * * 1 /选择/脚本/ script.sh
You can also use a comma to add multiple entries into a field.您也可以使用一个逗号添加多个条目到外地。 This is useful if you want to run a script thrice a day, with an eight hour interval.这是非常有用的如果你想运行一个脚本三次,每天8小时间隔。 Make sure you do not leave space between entries in a single field, though.请务必不要离开条目之间的空间在一个领域,但。 Your “cron job” entry would look like this:您的“作业”项目,将如下所示:
0 1,9,17 * 2,11 * /opt/scripts/db_backup_script.sh 0 1,9,17 * 2,11 * /选择/脚本/ db_backup_script.sh
In the above example the script “db_backup_script.sh” runs at 1 AM, 9 AM, and 5 PM every day in the months of February and November.在上面的例子中的脚本“ db_backup_script.sh ”运行在凌晨1时左右,上午9点,下午5点并每天在2月和11月。 There are a lot of cool things that you can do with cron jobs.有很多很酷的东西,你可以与玉米的就业机会。 The same works for day, month, and day of week.同样的工程,一天,月,日的一周。 Once you get the hang of this try out the following.一旦你的航这项尝试以下。 Crontab doesn’t only understand numbers, it can also operate on some basic English words: Crontab并不仅仅理解号码,还可以操作一些基本的英语单词:
string explanation字符串解释
—— ———– -- ---
@reboot Run once, the next time the system reboots @重新启动运行一次,下一次重新启动系统
@yearly Run once a year, at the beginning of the year @每年运行一年一次,在今年年初
@annually Same as @yearly, run once annually @每年相同@每年,每年举办一次
@monthly Run once a month, at the beginning of the month @每月运行每月一次,在本月初
@weekly Run once a week, at the beginning of the week @每周每周举办一次,在开始的一周内
@daily Run once a day, at midnight @日常运行每天一次,在午夜
@midnight Same as @daily, run at midnight午夜@ @同每天午夜运行
@hourly Run once an hour, at the beginning of the hour @每小时运行一次一个小时,开始时每小时
So, for example, if you want to run a script at midnight every night, this is what your crontab configuration would look like:因此,举例来说,如果你想运行一个脚本在午夜每天晚上,这就是你的crontab配置将如下所示:
@midnight /opt/scripts/script.sh @午夜/选择/脚本/ script.sh
Using “@midnight” rather than “0 0 * * *” will work the same and execute the requested script at midnight every night while being a lot more readable than its numerical counterpart.用“ @午夜” ,而不是“ 0 0 * * * ”将同样的工作和执行脚本所要求的在午夜每天晚上同时,更多的可读性比其对应的数值。 You can also make the use of hyphens to declare a range.您也可以使用连字号申报范围之内。 In the command below “script.sh” will be executed at the beginning of every hour from 1 AM to 6 AM:在命令下面的“ script.sh ”将被处死开始时每个小时从凌晨1点至6点:
0 1-6 * * * /opt/scripts/script.sh 0 1-6 * * * /选择/脚本/ script.sh
There are many more cool things you can do with cron.还有很多很酷的事情你能做的玉米。 Every sysasmin swears by it, it’s pretty easy to use once you get the hang on it, and very powerful.每sysasmin发誓的,它很容易使用一旦你的挂在它,非常强大。 Use this tool wisely, as scheduling a task wrongly can sometimes do a lot of harm.使用此工具明智的,因为一个任务调度错误,有时做了很多伤害。 Reading the “man page” of crontab would be highly recommended.读“男人的一页”的crontab将是非常推荐。






















{ 0 comments… ( 0评论... add one now现在添加一个 } )
Leave a Comment发表您的评论