liunx服务器系统为suse,以这个为例,每一步都进行过测试,请按照步骤来。
1.首先查看服务器crontab任务
crontab -l
出现上图,表示没有配置任何定时任务。
如果出现no crontab for root不用管
2.创建执行脚本
创建脚本命令hello.sh
例如:将时间输出到date1.txt文件中
#!/bin/bash
date >> /home/date1.txt
3.文件授权
对创建脚本授权
进入执行脚本文件目录下 cd /opt
将文件授权
chmod +x hello.sh
4.创建定时命令
输入crontab -e,执行插入操作
进行编辑页面,使用编辑命令 i插入 x删除 d删除一行,
输入
*/1 * * * * /opt/hello.sh
点击Esc退出当前编辑,输入:wq保存退出
这句话表示每一分钟执行opt下的hello.sh脚本
5.重启定时器
/sbin/service cron start 启动crontab
/sbin/service cron stop 停止crontab
/sbin/service cron restart 重新启动crontab
/sbin/service cron reload 重新载入crontab