Liunx下的定时任务【crond】
[例]crond 定时执行jar文件
1.创建一个shell脚本demo.sh
/*脚本内容为*/
source /etc/profile;
java -jar /opt/helloworld.jar; --执行在opt下的helloworld.jar
2.创建一个定时任务crontab
--打开编辑器
crontab -u root -e /crontab -e
--任务
59 23 * * * sh /opt/demo.sh [demo.sh 在opt下]
每天23点59分执行sh命令即执行jar文件
3.
service crond stop --停止crond服务
service crond start --开启crond服务
4.
crontab -l 显示当前时程表
crontab -r 删除当前里程表
5.
时程表的格式如下 :
f1[分钟] f2[小时] f3[日] f4[月] f5[年] program[程序/命令]
其中 f1 是表示分钟,f2 表示小时,f3 表示一个月份中的第几日,f4 表示月份,f5 表示一个星期中的第几天。program 表示要执行的程序或命令
。
当 f1 为 * 时表示每分钟都要执行 program,f2 为 * 时表示每小时都要执行程序,....
当 f1 为 a-b 时表示从第 a 分钟到第 b 分钟这段时间内要执行,f2 为 a-b 时表示从第 a 到第 b 小时都要执行,...
当 f1 为 */n 时表示每 n 分钟个时间间隔执行一次,f2 为 */n 表示每 n 小时个时间间隔执行一次,其馀类推
当 f1 为 a, b, c,... 时表示第 a, b, c,... 分钟要执行,f2 为 a, b, c,... 时表示第 a, b, c...个小时要执行,....
浙公网安备 33010602011771号