Linux

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > Linux > linux配置定时任务

linux配置定时任务全过程

作者:瀚高PG实验室

文章介绍了crontab命令在Linux系统中的使用方法和配置信息,包括定时任务的概念、查看服务、格式和语法,以及实例

环境

系统平台:Linux x86-64 Red Hat Enterprise Linux 8,Linux x86-64 Red Hat Enterprise Linux 7

版本:4.5.8

文档用途

详细介绍crontab命令的使用配置

详细信息

1.定时任务CRONTAB概念/介绍

2.查看定时任务服务

[root@hac1 ~]# systemctl status  crond.service 
● crond.service - Command Scheduler

   Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)

   Active: active (running) since Tue 2023-12-12 13:53:23 CST; 26min ago

 Main PID: 2999 (crond)

    Tasks: 1

   CGroup: /system.slice/crond.service

           └─2999 /usr/sbin/crond -n



Dec 12 13:53:23 hac1 systemd[1]: Started Command Scheduler.

Dec 12 13:53:23 hac1 crond[2999]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 81% if used.)

Dec 12 13:53:24 hac1 crond[2999]: (CRON) INFO (running with inotify support)

3.定时任务格式,语法

1)首先看下/etc/crontab 文件内容

[root@hac1 ~]# 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

2)语法

3)实例

#注意:

在定时任务配置文件中可以书写多行,每一行代表一个周期性任务。

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文