Linux Crontab Scheduled tasks to be organized and installed
yum install -y vixie-cron # 安装
Common commands
crontab -e # 编辑crontab -l # 查看crontab -u # 指定用户service crond start # 启动service crond stop # 关闭service crond restart # 重启service crond reload # 重载配置
Configuration
格式 * * * * * 分 时 日 月 星期(0-6)说明 * 所有取值范围内数字 / 每 - 某个数字 到 某个数字 , 分开几个离散的数字
Demo
*/5 * * * * php /home/www/test.php > /dev/null 2>&1
>/dev/null 2>&1 Analysis
标准输出重定向到空设备文件> 是重定向/dev/null 代表空设备文件1 表示stdout标准输出,系统默认值是1,所以 ">/dev/null" 等同于 "1>/dev/null"2 表示stderr标准错误& 表示等同于的意思,2>&1,表示2的输出重定向等同于1
Boot up
chkconfig --list crond # 是否开机启动查看添加开机启动 vi /etc/rc.d/rc.local 加 /sbin/service crond start
Crond cannot be restarted
killall crond crond restart
Crontab when the shell cannot execute
Shell in the head join Source/etc/profile
source /etc/profile#!/bin/bashcd /tmp/php test.php >> /tmp/test.log
Log location
Linux crontab Scheduled Task collation