Crontab安装和使用
安装crontab sh 复制代码 # 安装crontab yum install cronie -y 常用命令 如果使用service则使用下列命令 sh 复制代码 # 启动 service crond start # 停止 service crond stop # 重启 service crond restart # 运行状态 service crond status # 重新载入配置 service crond reload 如果使用systemctl则使用下列命令 sh 复制代码 # 启动 systemctl start crond # 停止 systemctl stop crond # 重启 systemctl restart crond # 运行状态 systemctl status crond # 开机启动 systemctl enable crond Crontab命令 sh 复制代码 # 编辑该用户的定时器配置 crontab -e # 列出该用户的计时器设置 crontab -l # 删除该用户的计时器设置 crontab -r # 指定要设定计时器的用户名称 crontab -u xujun 系统级 sh 复制代码 # 查看定时脚本 vi /etc/crontab 脚本说明 sh 复制代码 # 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 # 定时备份数据库(凌晨2点) 0 2 * * * root /data1/mysql/bak/bak.sh > /data1/mysql/bak/bak.log 2>&1 查看日志 sh 复制代码 # 查看运行日志 tail -f /var/log/cron