• linux下使用crontab新建定时任务


    我安装了一个全文搜索的插件,但是需要生成索引才能使用,但是不能手动生成索引,所以说呢,我就加了一个定时任务,

    一、首先vim /etc/crontab 打开文件

    我根据上面的提示加了用户名,但是看到其他的人写的都没加,不知道怎么回事,反正可以用我,哈为什么用sh文件呢,因为我得进入某个目录在执行文件,这样比较简单。

    二、描述:

    minute hour day month dayofweek command

        minute - 从0到59的整数
        hour - 从0到23的整数
        day - 从1到31的整数 (必须是指定月份的有效日期)
        month - 从1到12的整数 (或如Jan或Feb简写的月份)
        dayofweek - 从0到7的整数,0或7用来描述周日 (或用Sun或Mon简写来表示)
        command - 需要执行的命令(可用as ls /proc >> /tmp/proc或 执行自定义脚本的命令)

        root表示以root用户身份来运行
        run-parts表示后面跟着的是一个文件夹,要执行的是该文件夹下的所有脚本

    三、案例

    0 12 * * * service httpd restart   每天12点重启apache

    0 12 * * * service mysqld restart   每天12点重启mysql


    45 4 1,10,22 * *service httpd restart  每月1、10、22日的4 : 45重启apache

    10 1 * * 6,0 service httpd restart    每周六、周日的1 : 10重启apache

    0,30 18-23 * * *service httpd restart   每天18 : 00至23 : 00之间每隔30分钟重启apache

    0 23 * * 6 service httpd restart 每星期六的11 : 00 pm重启apache

    * 23-7/1 * * * service httpd restart 晚上11点到早上7点之间,每隔一小时重启apache

    0 11 4 * mon-wed service httpd restart 每月的4号与每周一到周三的11点重启apache

    0 4 1 jan * service httpd restart 一月一号的4点重启apache

    四、crontab服务的启动关闭

    sbin/service crond start //启动服务
    /sbin/service crond stop //关闭服务
    /sbin/service crond restart //重启服务
    /sbin/service crond reload //重新载入配置

    五、查看 crontab 任务:

    crontab -l
  • 相关阅读:
    Python 认识元组
    Python 认识字典
    Python 字符串中常见的一些方法续
    python 打印 A ~ Z
    Python3的print怎么让它不换行
    Python 中的 lstrip、rstrip、strip
    Python判断一个字符串是否包含指定字符串的方法
    Python 字符串中常见的一些方法
    Python 认识字符串
    苹果电脑MacbookPro双开微信!
  • 原文地址:https://www.cnblogs.com/xbxxf/p/7202057.html
Copyright © 2020-2023  润新知