cron Configuration-LINUX

这个解释得比较细致。。

http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/

How do I add cron job under Linux or UNIX like operating system?

Cron job are used to schedule commands to be executed periodically. You can setup commands or scripts, which will repeatedly run at a set time. Cron is one of the most useful tool in Linux or UNIX like operating systems. The cron service (daemon) runs in the background and constantly checks the /etc/crontab file, /etc/cron.*/ directories. It also checks the /var/spool/cron/ directory

crontab is the command used to install, deinstall or list the tables (cron configuration file) used to drive the cron daemon in Vixie Cron. Each user can have their own crontab file, and though these are files in /var/spool/cron/crontabs, they are not intended to be edited directly. You need to use crontab command for editing or setting up your own cron jobs.

Different Types of cron Configuration

There are two different types of configuration files:

  1. The UNIX / Linux system crontab : Usually, used by system services and critical jobs that requires root like privileges. The sixth field (see below for field description) is the name of a user for the command to run as. This gives the system crontab the ability to run commands as any user.
  2. The user crontabs: User can installer their own jobs using the crontab command. The sixth field is the command to run, and all commands run as the user who created the crontab

How Do I Install / Create / Edit My Own Cronjobs?

To edit your crontab file, type the following command at the UNIX / Linux shell prompt:
$ crontab -e

Syntax of crontab (Field Description)

Your cron job looks as follows for user jobs:

 
1 2 3 4 5 /path/to/command arg1 arg2
 

OR

 
1 2 3 4 5 /root/backup.sh
 

Where,

  • 1: Minute (0-59)
  • 2: Hours (0-23)
  • 3: Day (0-31)
  • 4: Month (0-12 [12 == December])
  • 5: Day of the week(0-7 [7 or 0 == sunday])
  • /path/to/command - Script or command name to schedule

Easy to remember format:

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

Your cron job looks as follows for system jobs:

1 2 3 4 5 USERNAME /path/to/command arg1 arg2

OR

1 2 3 4 5 USERNAME /path/to/script.sh

Example: Install Backup Job Script

If you wished to have a script named /root/backup.sh run every day at 3am, your crontab entry would look like as follows. First, install your cronjob by running the following command:
# crontab -e
Append the following entry:
0 3 * * * /root/backup.sh
Save and close the file.

More Examples

To run /path/to/command five minutes after midnight, every day, enter:
5 0 * * * /path/to/command
Run /path/to/script.sh at 2:15pm on the first of every month, enter:
15 14 1 * * /path/to/script.sh
Run /scripts/phpscript.php at 10 pm on weekdays, enter:
0 22 * * 1-5 /scripts/phpscript.php
Run /root/scripts/perl/perlscript.pl at 23 minutes after midnight, 2am, 4am ..., everyday, enter:
23 0-23/2 * * * /root/scripts/perl/perlscript.pl
Run /path/to/unixcommand at 5 after 4 every Sunday, enter:
5 4 * * sun /path/to/unixcommand

时间: 2024-10-31 00:24:00

cron Configuration-LINUX的相关文章

Linux Oracle to Exadata configuration

Linux Oracle to Exadata configuration Linux Oracle to Exadata configuration (Unidirectional) The diagram illustrates a configuration using a primary Extract process creating a remote trail on the target. The Replicat process applies the changes from

Linux下的Cron定时执行工具使用入门

cron是一个linux下的定时执行工具,可以在无需人工干预的情况下运行作业.由于Cron 是Linux的内置服务,但它不自动起来,可以用以下的方法启动.关闭这个服务: /sbin/service crond start //启动服务 /sbin/service crond stop //关闭服务 /sbin/service crond restart //重启服务 /sbin/service crond reload //重新载入配置 你也可以将这个服务在系统启动的时候自动启动: 在/etc/

Linux/UNIX 定时任务 cron 详解

导言 定时任务cron job被用于安排那些需要被周期性执行的命令.利用它,你可以配置某些命令或者脚本,让它们在某个设定的时间内周期性地运行.cron 是 Linux 或者类 Unix 系统中最为实用的工具之一.cron 服务(守护进程)在系统后台运行,并且会持续地检查 /etc/crontab 文件和 /etc/cron.*/目录.它同样也会检查/var/spool/cron/ 目录. crontab 命令 crontab 是用来安装.卸载或者列出定时任务列表的命令.cron 配置文件则用于驱

linux下用cron定时执行任务的方法_Linux

名称 : crontab 使用权限 : 所有使用者 使用方式 : crontab file [-u user]-用指定的文件替代目前的crontab. crontab-[-u user]-用标准输入替代目前的crontab. crontab-1[user]-列出用户目前的crontab. crontab-e[user]-编辑用户目前的crontab. crontab-d[user]-删除用户目前的crontab. crontab-c dir- 指定crontab的目录. crontab文件的格式

Linux 有问必答: 如何在Linux中加入cron任务

Linux 有问必答: 如何在Linux中加入cron任务 提问: 我想在我的Linux中安排一个计划任务,该任务在固定时间周期性地运行.我该如何在Linux中添加一个cron任务? cron是Linux中默认的计划任务.使用cron,你可以安排一个计划(比如:命令或者shell脚本)周期性地运行或者在指定的分钟.小时.天.周.月等特定时间运行.cron在你安排不同的常规维护任务时是很有用的,比如周期性地备份.日志循环.检查文件系统.监测磁盘空间等等. (题图来自 eagleapex.com)

linux系统中Cron Job使用方法详解

cron是linux的一个daemon,cron job就是被cron预定执行的任务.cron使用特殊的配置文件即crontab文件来设置命令或脚本的执行时间或频率.之前已经介绍crontab的基础使用,不再详述. 再次说明下crontab的命令格式  # ┌───────────── min (0 - 59)  # │ ┌────────────── hour (0 - 23)  # │ │ ┌─────────────── day of month (1 - 31)  # │ │ │ ┌──

magento -- 1.4下的计划任务(cron job)

  On some points, Magento needs regular maintenance. For instance, when running a shop of which the products are updated frequently, it is needed to refresh catalog indices. Also the search-index might need regular updating. To accomplish these tasks

加强企业Linux系统安全的若干方法

世界上没有绝对安全的系统,即使是普遍认为稳定的Linux系统,在管理和安全方面也存在不足之处.我们期望让系统尽量在承担低风险的情况下工作,这就要加强对系统安全的管理.为了帮助企业了解和掌握如何加强Linux系统在安全方面的管理,除了把预防工作提前做好外,还需要了解黑客常用手法. 下面,分别从黑客对Linux的入侵攻击和Linux系统的安全防护两个方面来介绍如何加强Linux系统在安全方面的管理. 防止黑客的入侵 在谈黑客入侵方面的安全管理之前,简单介绍一些黑客攻击Linux主机的主要途径和惯用手

如何加强企业Linux系统安全

  黑客对Linux的入侵攻击和Linux系统的安全防护两个方面内容将是我们为大家阐述的主题,从而使大家了解如何加强Linux系统在安全方面的管理. 防止黑客的入侵Linux主机 在谈黑客入侵方面的安全管理之前,简单介绍一些黑客攻击Linux主机的主要途径和惯用手法,让大家对黑客攻击的途径和手法有所了解.这样才能更好地防患于未然,做好安全防范. 要阻止黑客蓄意的入侵,可以减少内网与外界网络的联系,甚至独立于其它网络系统之外.这种方式虽造成网络使用上的不便,但也是最有效的防范措施. 黑客一般都会寻