zoukankan      html  css  js  c++  java
  • Shell命令_Cron使用


    chkconfig crond on
    d表示damon,后台进程
    chkconfig --list | grep crond

    crontab [选项]
    选项:
    -e: 编辑crontab定时任务
    -l: 查询crontab任务
    -r: 删除当前用户所有的crontab任务

    步骤:
    1、创建cron任务
    crontab -e
    */1 * * * * echo "Have a break now." >> /tmp/test.txt

    2、启动任务
    /sbin/service crond start
    修改crontab内容后无需重启服务

    3、添加定期执行脚本
    crontab -e
    */1 * * * * sh /usr/local/src/shscripts/hello.sh
    脚本内容:
    #!/bin/sh
       echo "定期执行脚本输出内容." >> /tmp/test3.txt

    4、查看cron运行日志
    vim /var/log/cron

    5、查看定时任务
    crontab -l

    一、crond命令
    /sbin/service crond start //启动服务  
    /sbin/service crond stop //关闭服务  
    /sbin/service crond restart //重启服务  
    /sbin/service crond reload //重新载入配置
    /sbin/service crond status //服务状态

    二、crontab命令
    crontab -u //设定某个用户的cron服务,一般root用户在执行这个命令的时候需要此参数
    crontab -l //列出某个用户cron服务的详细内容    
    crontab -r //删除没个用户的cron服务    
    crontab -e //编辑某个用户的cron服务
    

    三、crontab表达式
    0 */2 * * * echo "Have a break now." >> /tmp/test.txt 每隔2小时执行一次
    */1 * * * * echo "Have a break now." >> /tmp/test.txt 每隔1分钟执行一次
    # crontab基本格式
    # +---------------- minute  分钟(0 - 59)
    # |  +------------- hour    小时(0 - 23)
    # |  |  +---------- day     日期(1 - 31)
    # |  |  |  +------- month   月份(1 - 12)
    # |  |  |  |  +---- week    星期(0 - 7) (星期天=0 or 7)
    # |  |  |  |  |
    # *  *  *  *  *  要运行的命令




  • 相关阅读:
    数据库自动备份(转)
    sqlserver常用全局变量
    Remoting通讯实例
    自定义ORM框架(转转)
    带格式导出数据到Excel
    app.config动态修改及读取
    学习笔记之AJAX无刷新分页
    游标(转转)
    Sql Server索引(转载)
    流Stream个人学习理解
  • 原文地址:https://www.cnblogs.com/gossip/p/6045632.html
Copyright © 2011-2022 走看看