Linux学习8----定时任务

计划任务

定时任务,可以设置固定的时间去执行

默认每分钟检查一次

检查

rpm -qa cron*  #定时任务是否安装

systemctl status crond #定时任务是否在运行

systemctl is-active crond #定时任务是否在运行

ps aux|grep crond #查询进行中的定时任务

软件

at

定时任务工具,依赖于atd服务,适用于执行一次就结束的调度任务

crond

需要读取配置文件,有固定的文件格式,通过crontab命令管理文件

  • 系统定时任务

    /etc/cron.d   #系统定时任务目录
    /etc/anacrontab  #系统定时任务目录
    
  • 用户定时任务

    /var/spool/cron/ #用户定时任务目录
    
语法
[root@centos ~]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed/文件绝对路径

crontab命令
参数 含义 使用示例
-l list 查看定时任务 crontab -l
-e edit 编辑定时任务 crontab -e
-i 删除定时任务,提示用户确认删除,避免出错 crontab -i
-r 删除定时任务,移除/var/spool/cron/username文件,全没了 crontab -r
-u 指定用户执行任务,root可以管理普通用户计划任务 crontab -u root -l
posted @   shog808  阅读(3)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示