[root@root test]# pwd
/home/admin/test
[root@root test]# crontab -l
00 02 * * * sh /home/admin/optbash/dailyBackup.sh
00 02 * * * sh /home/admin/optbash/deleteDebugSql.sh
[root@root test]# touch test.sh
[root@root test]# vim test.sh
/bin/echo `date` > /home/admin/test/console.txt
[root@root test]# ll
total 8
-rw-r--r-- 1 root root 29 Mar 27 21:31 console.txt
-rwxr-xr-x 1 root root 48 Mar 27 21:28 test.sh
[root@root test]# chmod +x ./test.sh
[root@root test]# crontab -e
00 02 * * * sh /home/admin/optbash/dailyBackup.sh
00 02 * * * sh /home/admin/optbash/deleteDebugSql.sh
* * * * * sh /home/admin/test/test.sh
"/tmp/crontab.HauiiV" 3L, 143C written
crontab: installing new crontab
[root@root test]# crontab -l
00 02 * * * sh /home/admin/optbash/dailyBackup.sh
00 02 * * * sh /home/admin/optbash/deleteDebugSql.sh
* * * * * sh /home/admin/test/test.sh
[root@root test]#
[root@root test]# vim console.txt
Fri Mar 27 21:40:01 EDT 2015
基本格式 :
* * * * * command
分 时 日 月 周 命令
1、每分钟执行一次
* * * * *
2、每隔一小时执行一次
00 * * * *
or
* */1 * * * (/表示频率)
3、每小时的15和30分各执行一次
15,45 * * * * (,表示并列)
4、在每天上午 8- 11时中间每小时 15 ,45分各执行一次
15,45 8-11 * * * command (-表示范围)
5、每个星期一的上午8点到11点的第3和第15分钟执行
3,15 8-11 * * 1 command
6、每隔两天的上午8点到11点的第3和第15分钟执行
3,15 8-11 */2 * * command
名称 : 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的目录。
yum install crontabs
服务操作说明:
/sbin/service crond start //启动服务
/sbin/service crond stop //关闭服务
/sbin/service crond restart //重启服务
/sbin/service crond reload //重新载入配置
查看crontab服务状态:
service crond status
手动启动crontab服务:
service crond start
查看crontab服务是否已设置为开机启动,执行命令:
ntsysv
加入开机自动启动:
chkconfig –level 35 crond on