centos中的定时任务

1. 定时服务的启动与关闭

  • 启动:systemctl start crond.service
  • 查看状态:systemctl status crond.service
  • 停止:systemctl stop crond.service
  • 重新启动:systemctl restart crond.service
  • 重新加载:systemctl reload crond.service

当然你如果熟悉CentOS6的命令,也可以输入如下命令,其实这个命令就是调用了我们上面的命令。

  • service crond start
  • service crond stop
  • service crond restart
  • service crond reload

2. 定时服务的增删改查

启动之后,它的使用是非常简单的。

crontab [选项]
 crontab -l 查看当前用户的crontab  crontab –e 编辑crontab  crontab –r  删除crontab  crontab –e  添加任务

可以看到现在这个文件里面完全为空,你只要按照我们的标准格式写入我要执行的系统变量,它就可以在指定的时间执行,那么这个标准是什么,看一下。

3. 基本格式

基本格式:*  *  *  *  *  command

例子:
# 每月的最后1天 0 0 L * *  说明: Linux * * * * * - - - - - | | | | | | | | | +----- day of week (0 - 7) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat | | | +---------- month (1 - 12) OR jan,feb,mar,apr ... | | +--------------- day of month (1 - 31) | +-------------------- hour (0 - 23) +------------------------- minute (0 - 59)

猜你喜欢

转载自www.cnblogs.com/leizhi/p/12449508.html