【Linux系统】Crontab计划任务-常见命令详解

3,417
IPRoyal

Crontab是Linux系统下的定时计划程序,可以让系统在指定时间去执行指定的某个操作,比如:定时重启系统、备份网站、执行某个脚本等,crond常常在后台运行,每一分钟检查是否有预定的作业需要执行。这类作业一般称为cron jobs。

一、Crontab设置

1、查看crontab定时执行任务列表文章源自技术白-https://jishubai.com/79.html

crontab -l

2、编辑crontab定时执行任务文章源自技术白-https://jishubai.com/79.html

crontab -e

3、删除crontab定时任务文章源自技术白-https://jishubai.com/79.html

crontab -r

4、相关命令:文章源自技术白-https://jishubai.com/79.html

sudo service crond start     #启动服务
sudo service crond stop      #关闭服务
sudo service crond restart   #重启服务
sudo service crond reload    #重新载入配置
sudo service crond status    #查看服务状态

二、Crontab基本格式语法

crontab 的时间表达式:文章源自技术白-https://jishubai.com/79.html

基本格式 :
*  *  *  *  *  command
分  时  日  月  周   命令

举例说明,每天凌晨3:00执行重启服务器:0 3 * * * reboot  ,其中reboot是命令,格式根据下图所示;文章源自技术白-https://jishubai.com/79.html

【Linux系统】Crontab计划任务-常见命令详解

crontab还有操作符,用来实现一些复杂的时间设定需要。操作符有:文章源自技术白-https://jishubai.com/79.html

  • *  取值范围内的所有数字 ,代表所有;
  • /  每过多少个数字 ,代表每隔n长时间;
  • -  从X到Z ,代表一段时间范围;
  •  散列数字,代表分割开多个值;

具体设置不会的可以百度谷歌下 crontab表达式生成 或访问https://cron.qqe2.com/文章源自技术白-https://jishubai.com/79.html 文章源自技术白-https://jishubai.com/79.html

本站TG群组skill_blog   联系博主:nbskill (微信协助) 杂货铺曙光商店

IPRoyal
 
技术白