1,lsattr -a crontab 查看 crontab 文件的属性,如果有 i 表示 root 用户不能编辑 crontab 文件
2,chattr -i crontab 去掉 crontab 文件的i属性
3,使用 root 用户编辑该文件,在文件中加入调度要执行的任务: 比如 */1 * * * * root /root/echo.sh 表示每分钟执行 /root/echo.sh 脚本
4, /root/echo.sh 脚本中加入 echo "你好" >> /root/1.txt ,输出“你好”打 1.txt 文件
5,以上表示每分钟输出 “你好” 到文件 1.txt 文件中
6,service crond start 启动服务即可开始执行调度任务
service crond stop 停止调度
service crond restart 重启调度
service crond status 查看 cron 的启动状态, cron 是 linux 操作系统自带的
7,如果没有安装
- yum install vixie-cron // vixie-cron 软件包是 cron 的主程序;
- yum install crontabs // crontabs 软件包是用来安装、卸装、或列举用来驱动 cron 守护进程的表格的程序。
- 然后启动 crond 服务即可