* * * * *
command 分 时 日 月 周 命令 第1列表示分钟1~59 (每分钟用*或者 /1表示,/5 表明每5分钟) 第2列表示小时1~23(0表示0点) 第3列表示日期1~31 第4列表示月份1~12 第5列标识号星期0~6(0表示星期天) 第6列要运行的命令php
crontab -l #查看计划任务列表 crontab -e #进入编辑计划任务模式 grep 'SSH' /var/spool/cron/root &>/dev/null ||echo '*/5 * * * * sh /root/SSH_Deny_Rule.sh' >> /var/spool/cron/root #没有添加任务时追加一个
<!--more-->mysql
#!/bin/bash while true do command sleep 20 ###睡眠20秒执行一次 done while true ;do /home/aide.sh >/dev/null 2>&1 sleep 7200 #2小时检测 done
* * * * * sleep 10; php /home/php/crontab/tolog.php
linux
0 1 * * * /root/backup_mysql.sh 凌晨1点备份 30 21 * * * /usr/local/etc/rc.d/lighttpd restart 每晚的21:30重启apache。 45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart 每个月一、十、22日的4 : 45重启apache。 10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart 每周6、周日的1 : 10重启apache。 0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart 在天天18 : 00至23 : 00之间每隔30分钟重启apache。 0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart 每星期六的11 : 00 pm重启apache。 * */1 * * * /usr/local/etc/rc.d/lighttpd restart 每一小时重启apache * 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart 晚上11点到早上7点之间,每隔一小时重启apache 0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart 每个月的4号与每周一到周三的11点重启apache 0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart 一月一号的4点重启apache
cat /etc/crontab
01 * * * * root run-parts /etc/cron.hourly 02 4 * * * root run-parts /etc/cron.daily 22 4 * * 0 root run-parts /etc/cron.weekly 42 4 1 * * root run-parts /etc/cron.monthly
咱们可在此文件中添加本身须要的cron job. /etc/cron.deny文件就是用于控制不让哪些用户使用Crontab的功能. 用户配置文件 每一个用户都有本身的cron配置文件,经过crontab -e 就能够编辑,通常状况下咱们编辑好用户的cron配置文件保存退出后,系统会自动就存放于/var/spool/cron/目录中,文件以用户名命名. linux的cron服务是每隔一分钟去读取一次/var/spool/cron,/etc/crontab,/etc/cron.d下面全部的内sql
at now+10 minutes #10分钟任务 at 5pm+3 days #3天下午5点任务 at>命令行 at> ctrl +d (退出) at -l #查看列表 at -c 2 #查看详细任务 at -d 2 #删除条目2的计划任务