From 50ee769861dc59c053936d466ad6d6e8e0c28713 Mon Sep 17 00:00:00 2001 From: zhengsihua Date: Fri, 23 Jan 2015 10:34:07 +0800 Subject: [PATCH] translated --- ...Answers--How to add a cron job on Linux.md | 68 ------------------- ...Answers--How to add a cron job on Linux.md | 66 ++++++++++++++++++ 2 files changed, 66 insertions(+), 68 deletions(-) delete mode 100644 sources/tech/20150122 Linux FAQs with Answers--How to add a cron job on Linux.md create mode 100644 translated/tech/20150122 Linux FAQs with Answers--How to add a cron job on Linux.md diff --git a/sources/tech/20150122 Linux FAQs with Answers--How to add a cron job on Linux.md b/sources/tech/20150122 Linux FAQs with Answers--How to add a cron job on Linux.md deleted file mode 100644 index ad861b42c7..0000000000 --- a/sources/tech/20150122 Linux FAQs with Answers--How to add a cron job on Linux.md +++ /dev/null @@ -1,68 +0,0 @@ -Translating----geekpi - -Linux FAQs with Answers--How to add a cron job on Linux -================================================================================ -> **Question**: I would like to schedule a task on my Linux box, so that the task runs periodically at fixed times. How can I add a cron job for this task on my Linux system? - -The cron utility is the default task scheduler used in Linux. Using cron, you can schedule a task (e.g., a command or a shell-script) to run it periodically or one-time at a specific time of hour, day, week, month, etc. The cron tool is useful when you schedule a variety of regular maintenance jobs, such as periodic backup, rotating logs, checking filesystem, monitoring disk space, and so on. - -### Add a Cron Job from the Command Line ### - -To add a cron job, you can use a command-line tool called crontab. - -Type the following command to create a new cron job to run as the current user. - - $ crontab -e - -If you want a cron job to run as any other user, type the following command instead. - - $ sudo crontab -u -e - -You will be presented with a text editor window, where you can add or edit cron jobs. By default, nano editor will be used. - -![](https://farm9.staticflickr.com/8586/16200331362_1385807ac0_b.jpg) - -Each cron job is formatted as follows. - - - -The first five elements specify the schedule for a task, and the last element is the (full-path) command or script to execute according to the schedule. - -![](https://farm8.staticflickr.com/7472/16199272841_dffe0b2873_b.jpg) - -Here are a few useful cron job examples. - -- *** * * * * /home/dan/bin/script.sh**: run every minute. -- **0 * * * * /home/dan/bin/script.sh**: run every hour. -- **0 0 * * * /home/dan/bin/script.sh**: run at 12am daily. -- **0 9,18 * * * /home/dan/bin/script.sh**: run at 9AM and 6PM twice a day. -- **0 9-18 * * * /home/dan/bin/script.sh**: run every hour from 9AM and 6PM. -- **0 9-18 * * 1-5 /home/dan/bin/script.sh**: run every hour from 9AM and 6PM every weekday. -- ***/10 * * * * /home/dan/bin/script.sh**: run every 10 minutes. - -Once you are done with setting up cron job(s), press Ctrl+X to save and quit the editor. At this point, newly added cron jobs should be activated. - -To browse existing cron jobs of yours, use the following command: - - $ crontab -l - -### Add a Cron Job from GUI ### - -If you are in Linux desktop environment, you can use a GUI fronend for crontab to add or edit a cron job via a more user-friendly interface. - -On GNOME desktop, there is GNOME Schedule (gnome-schedule package). - -![](https://farm8.staticflickr.com/7484/16015054699_d96f0e9b6a_c.jpg) - -On KDE desktop, there is Task Scheduler (kcron package). - -![](https://farm8.staticflickr.com/7473/16175298266_825376c901_c.jpg) - --------------------------------------------------------------------------------- - -via: http://ask.xmodulo.com/add-cron-job-linux.html - -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出 \ No newline at end of file diff --git a/translated/tech/20150122 Linux FAQs with Answers--How to add a cron job on Linux.md b/translated/tech/20150122 Linux FAQs with Answers--How to add a cron job on Linux.md new file mode 100644 index 0000000000..6f0a5effe3 --- /dev/null +++ b/translated/tech/20150122 Linux FAQs with Answers--How to add a cron job on Linux.md @@ -0,0 +1,66 @@ +Linux 有问必答: 如何在Linux中加入cron任务 +================================================================================ +> **提问**: 我想在我的Linux中安排一个计划任务,该任务在固定时间周期性地运行。我该如何在Linux中添加一个cron任务? + +cron是Linux中默认的计划任务。使用cron,你可以安排一个计划(比如:命令或者shell脚本)周期性地运行或者在指定的小时、天、周、月等特定时间运行。cron在你安排不同的常规维护任务时是很有用的,比如周期性地备份、日志循环、检查文件系统、监测磁盘空间等等。 + +### 从命令行中添加cron任务 ### + +要添加cron任务,你可以使用称为crontab的命令行工具。 + +输入下面的命令会创建一个以当前用户运行的新cron任务。 + + $ crontab -e + +如果你想要以其他用户运行cron任务,输入下面的命令。 + + $ sudo crontab -u -e + +你将会看见一个文本编辑窗口,这里你可以添加或者编辑cron任务。默认使用nono编辑器。 + +![](https://farm9.staticflickr.com/8586/16200331362_1385807ac0_b.jpg) + +每个cron任务的格式如下。 + + + +前5个元素定义了任务的计划,最后一个元素是命令或者脚本的完整路径。 + +![](https://farm8.staticflickr.com/7472/16199272841_dffe0b2873_b.jpg) + +下面是一些cron任务示例。 + +- *** * * * * /home/dan/bin/script.sh**: 每分钟运行。 +- **0 * * * * /home/dan/bin/script.sh**: 每小时运行。 +- **0 0 * * * /home/dan/bin/script.sh**: 每12小时运行。 +- **0 9,18 * * * /home/dan/bin/script.sh**: 在每天的9AM和6PM运行。 +- **0 9-18 * * * /home/dan/bin/script.sh**: 在9AM到6PM的每个小时运行。 +- **0 9-18 * * 1-5 /home/dan/bin/script.sh**: 周一到周五的9AM到6PM每小时运行。 +- ***/10 * * * * /home/dan/bin/script.sh**: 每10分钟运行。 + +一旦完成上面的设置步骤后,按下Ctrl+X来保存并退出编辑器。此时,新增的计划任务应该已经激活了。 + +要查看存在的计划任务,使用下面的命令: + + $ crontab -l + +### 从GUI添加计划任务 ### + +如果你在Linux桌面环境中,你可以使用crontab的更加友好的GUI前端来添加或者添加一个cron任务。 + +在Gnome桌面中,有一个Gnome Schedule(gnome-schedule包)。 + +![](https://farm8.staticflickr.com/7484/16015054699_d96f0e9b6a_c.jpg) + +在KDE桌面中,有一个Task Scheduler(kcron包)。 + +![](https://farm8.staticflickr.com/7473/16175298266_825376c901_c.jpg) + +-------------------------------------------------------------------------------- + +via: http://ask.xmodulo.com/add-cron-job-linux.html + +译者:[geekpi](https://github.com/geekpi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出 \ No newline at end of file