首页 > 其他分享 >Execute Crond Service on openEuler

Execute Crond Service on openEuler

时间:2022-11-28 15:00:13浏览次数:43  
标签:Execute Service ## cmd 00 crontab crond 定时 Crond

一、Execute Crond Service on openEuler

1 crond 概述

crond就是计划任务/定时任务

常见有闹钟、PC端定时关机 shutdown -s -t 200,定时执行

计划任务执行一些周期性的任务,夜深人静时,给服务器数据文件做定时备份数据,某个时间段有活动开启接口/关闭接口

使用情况

  • 临时文件清理、系统信息采集、日志文件切割
  • 定时向互联网同步时间,定时备份系统配置文件,定时备份数据库的数据

2 检查服务状态

## 检查是否安装
[root@ecs-65685 ~]# rpm -qf `which crond`
cronie-1.5.4-5.oe1.x86_64

## 最小化服务已安装 crond,系统基础服务之一
systemctl status crond
## 
systemctl enable crond
systemctl start crond
systemctl restart crond

3 crontab 配置文件记录时间周期的含义

## 定时任务的格式
[root@ecs-65685 ~]# 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

## 帮助命令
[root@ecs-65685 ~]# man 4 crontabs

[root@ecs-65685 ~]# crontab --help
crontab: invalid option -- '-'
crontab: usage error: unrecognized option
Usage:
 crontab [options] file
 crontab [options]
 crontab -n [hostname]

Options:
 -u <user>  define user
 -e         edit user's crontab
 -l         list user's crontab
 -r         delete user's crontab
 -i         prompt before deleting
 -n <host>  set host in cluster to run users' crontabs
 -c         get host in cluster to run users' crontabs
 -s         selinux context
 -V         print version and exit
 -x <mask>  enable debugging

Default operation is replace, per 1003.2

4 定时任务规则/案例

## *  *  *  *  *  command
## 分  时  日  月   周   命令
## 1 表示分钟1~59 每分钟用*或者 */1表示
## 2 表示小时1~23 [0-23]
## 3 表示日期1~31 
## 4 表示月份1~12 [jan,feb,mar,apr,...]
## 5 标识星期0~6  [sun,mon,tue,wed,thu,fri,sat]
## 6 运行的命 [df -h]

## * 任意时间 每 每分钟 每小时 每天 每周 每月
## /n 每隔/间隔多久执行一次
## ,[逗号] 分割时段独立时间
## -[减号] 区间范围

## Go to bed at 10 every night
00 10 * * * sleep

## 每隔十分钟执行一次
*/10 * * * * cmd

## 每隔3小时检查磁盘使用率
00 */3 * * * df -h

## 每天 20,21,22 点的整点执行命令
00 20-22 * * * cmd

## 每天凌晨5和晚上20,22点的30分时执行命令
30 05,20,22 * * * cmd

## 下午14点到23点每两个小时执行命令
00 13-23/2 * * * cmd
00 14,16,18,20,22,00 * * * cmd

## 早上9点到11点和下午14点到20点,每2个小时执行命令
00 09-11,14-20/2 * * * cmd

## 每年的2月14日的3点执行命令
00 03 14 2 * cmd

## 每年 1,3,6月的每天凌晨2点执行命令
00 02 * 1,3,6 * cmd

## 每年的4,5,6月的周五的凌晨5点执行命令
00 05 * 4,5,6 5 cmd

## 不推荐同时书写日期和周几

 

二、Crontab 编写cron定时任务

参数 含义
-e 编辑定时任务
-l 当前用户的定时任务
-r 清空/删除当前用户的所有定时任务
-o 指定其他用户

1 每分钟执行内容写入文件中

## 配置定时任务文件/创建定时任务
crontab -e
## echo email to file
*/1 * * * * /usr/bin/echo [email protected] &>> /tmp/xyz.txt

## 保存配置并即刻生效
crontab /etc/crontab

## 查看定时任务
crontab -l

## 测试与检查
tail -f /tmp/xyz.txt

## 检查定时任务的日志
tile -f /var/log/cron

2 每五分钟执行一次时间同步 ntpdate

##
dnf search ntp
dnf install ntpdate

crontab -e
## ntpdate time
*/1 * * * * /usr/sbin/ntpdate ntp1.aliyun.com &> /dev/null
##
crontab -l
##
date

3 

 

 

 

 

 

 

 

 

 

 

X、One Step Success

 

 

 

Y、Error message

 

 

Z、Related Links

 

标签:Execute,Service,##,cmd,00,crontab,crond,定时,Crond
From: https://www.cnblogs.com/huaxiayuyi/p/16931669.html

相关文章

  • WCF 4.0路由服务Routing Service
    在面向服务的应用系统中,最重要的概念就是消息,消息的传输是一个非常重要的问题。而在大多数情况下,消息要经历多个网络节点,这里会涉及到消息路由问题。WS规......
  • ClusterIP类型的Service
    Service使用实验环境准备在使用service之前,首先利用Deployment创建出3个pod,注意要为pod设置`app=nginx-pod`的标签创建deployment.yaml,内容如下:apiVersion:apps/v1k......
  • ServiceEntry和workloadentry
    部署client[root@masterServiceEntry-and-WorkloadEntry]#kubectlapply-f00-Deploy-Client/deployment.apps/clientcreatedservice/clientcreated[root@master......
  • System.Runtime.InteropServices浅见
    System.Runtime.InteropServices提供了相应的类或者方法来支持托管/非托管模块间的互相调用。System.Runtime.InteropServices中几个比较重要的类:DllImportAttribute: 该......
  • 调试Windows Service
       通常的处理办法是,在service运行后,在调试器中选择attachtoprocess.   然而这种做法也有一定的局限性,例如在service启动时的OnSta......
  • Service详解之Service介绍
    Service介绍在kubernetes中,pod是应用程序的载体,我们可以通过pod的ip来访问应用程序,但是pod的ip地址不是固定的,这也就意味着不方便直接采用pod的ip对服务进行访问。为了解......
  • WebService传输DataSet的一点想法和实践-.NET教程,Web Service开发
    其实这个标题很大,实现起来也可以有许多的办法。甚至,应否这样做也许都能惹出许多的争论(比如,为什么用ws而不是remoting?为什么传dataset而不是entity[]?)。      由于ds......
  • Failed to start mysqld.service: Unit not found
    转载自:https://blog.csdn.net/miaodichiyou/article/details/99289160 ========================= 很多人对本博客的方法提出了质疑,在此我解释一下:由于MySQL在CentO......
  • K8s系列---【什么是Service?】
    什么是Service?1.作用Service为一组pod提供服务发现与负载均衡,当有pod可用时,Service的服务发现能感知到,当外部请求进来时,Service的负载均衡功能能够轮流分发流量。并且能......
  • 【Azure Fabric Service】Service Fabric 托管群集通过
    问题描述ServiceFabric托管群集,使用KeyVault中证书,把证书导入到本地安装后,使用该证书的Thumbprint作为指令 Connect-ServiceFabricCluster 的 ServerCertThumbpr......