• linux crond定时任务


    1.crond服务管理

    crond服务启动:service
    crond restart( systemctl restart crond)

    crond服务查看:ps aux|grep crond

    设置开机自启动:chkconfig crond onsystemctl enable crond.service

    查看开机自启动状态:chkconfig --list|grep crond(systemctl list-unit-files|grep crond)

    2.crontab命令使用

    crontab [选项]

    选项:-e编辑定时任务

    -l显示定时任务

    -r删除定时任务

    定时任务,命令格式

    * * * * * 执行的任务(命令或shell脚本)

    注:

    1) 第一个*,表示一个小时中第几分钟,取值0-59

    第二个*,表示一天中第几个小时,取值0-23

    第三个*,表示一个月中第几天,取值1-31

    第四个*,表示一年中第几个月,取值1-12

    第五个*,表示一周中星期几,取值1-7

     

    2表示不连续的时间,例如1,2,4,8 * * * * echo m>>1.txt

    -表示连续的时间,例如 1-3 * * * * echo m>>1.txt

    */n表示每隔多久执行,例如*/5 * * * 1 echo m>>1.txt

     

    思考:0 0 1,15 * 1 执行的任务 含义?

     

    3.举例

     

    3.1 定时执行命令

    */3 * * * * /root/wrk/wrk -t2000 -c2000
    -d90s -v "https://XXXX.com/XXX"

    3.2 定时执行脚本

    */3 * * * * /root/sh/sni.sh

    #!/bin/bash
    
    i=0
    
    while [ $i -le 500 ]
    
    do
    
    curl -v https://huana1.test.cdn.aliyunlive.com/conn
    -k |grep connection_id>>/root/sh/hn1.txt
    
    echo $i huana1.test.cdn.aliyunlive.com
    >>/root/sh/hn1.txt
    
    echo $i $(date) >>/root/sh/hn1.txt
    
    i=$(( $i+1))
    
    done 
    注: 
    1)chmod修改脚本可执行权限; 2)文件路径建议用绝对路径;
     
  • 相关阅读:
    MySQLSource-Flume
    Flume
    Hive| ETL清洗& 查询练习
    Hive-04 压缩| 存储
    Hive-03 查询
    Hive-02 DDL| DML
    shell基本用法
    Hive-01 配置| 架构原理
    HDFS-HA高可用 | Yarn-HA
    react-路由和Ant design
  • 原文地址:https://www.cnblogs.com/shadow-yin/p/14842939.html
Copyright © 2020-2023  润新知