定义
cron是系统主要的调度进程,可以在无需人工干预的情况下运行作业。crontab命令允许用户提交、编辑或删除相应的作业。每一个用户都可以有一个crontab文件来保存调度信息。系统管理员可以通过cron.deny 和 cron.allow 这两个文件来禁止或允许用户拥有自己的crontab文件。
- crontab 服务
[root@etl_hadoop cron]# /etc/init.d/crond status
crond (pid 2199) is running...
- 查看当前用户的定时任务
[root@etl_hadoop cron]# crontab -l
# insert test log to /tmp/testlog/test.log
*/1 * * * * sh /tmp/testlog/log_generation.sh
- 编辑当前用户的定时任务
[root@etl_hadoop cron]# crontab -e
# insert test log to /tmp/testlog/test.log
*/1 * * * * sh /tmp/testlog/log_generation.sh
~
~
- 删除当前用户的定时任务
[root@etl_hadoop cron]# crontab -r
[root@etl_hadoop cron]# crontab -l
no crontab for root
- crontab文件一般位于/etc/crontab下,这里面存放系统运行的的调度程序
[root@etl_hadoop cron]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
- 每个用户自动生成一个自己的crontab文件,一般位于/var/spool/cron目录下
[root@etl_hadoop cron]# cat /var/spool/cron/root
16 1 * * 6 /usr/sbin/ntpdate ntp.bohailife.net>>/tmp/log;/sbin/hwclock -w
*/5 * * * * /usr/sbin/lsof -n|awk '{print $2}'|sort|uniq -c |sort -nr|awk 'NR==1'|awk '{print $1}' >/tmp/lsof.out







网友评论