zoukankan      html  css  js  c++  java
  • crontab

    1.计划任务


        系统中需要设定脚本的执行时,需要crontab。“# crontab -h”一下。

        crontab [-u user] file  (在脚本中需要添加一条任务的语法格式)

        crontab [-u user] [ -e | -l | -r]

        -u : 指定用户名

        -e : 编辑执行的内容

        -l : 列出已设定要执行的内容

        -r : ***已设定要执行的内容

        file : 是要求格式像“crontab -e”时手写输入的格式。执行上边的命令会“冲掉”(>)原有的设定。

          需要在脚本中添加任务,是应该把需要添加的内容写入一个文本

    文件file,然后使用该语法格式来载入 执行队列。

    需要修改设定,比如增加一条需要执行的指令:#!/bin/sh

    # 设定一个临时文件,用来暂时保存现有的任务设定。

    f_tm="/home/$USER/tem_file"

    # 任务的执行以那个用户身份执行的

    # 查询用户的任务 “crontab -u sunny -l”

    u_c="$USER"

    # 保存该用户目前的设定

    crontab -u $u_c -l > $f_tm

    # 添加新的任务。就是“crontab -e”执行后需要需如的内容。

    # 保存为文本文件。

    read -p "Input command that adding one: " add_com

    echo "$add_com" >> $f_tm

    # 从临时文件中读取任务设定信息。

    crontab -u $u_c $f_tm

    #test 

    #read ddy

    # ***临时文件

    rm -f $f_tm &> /dev/null

    # 显示任务设定修改后的内容。

    echo "The values for "crontab -l": "
    crontab -u $u_c -l

    2.crontab -e


      日期时间域有效值

    # 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
    View Code


      使用命令“
    vlinkstatus -w”每五分钟收集一次信息 

    # crontab -e
    */5 * * * * vlinkstatus -w
    # crontab -l
    */5 * * * * vlinkstatus -w
    一切代码都是为了生活,一切生活都是调剂
  • 相关阅读:
    MySql创建库 Challenge
    未能启用约束。一行或多行中包含违反非空、唯一或外键约束的值的解决办法.
    小总结:用反射机制创建的分配数据分配器
    工厂模式的反思
    单机安装“完整”SharePoint 2010
    作业调度框架 Quartz.NET 2.0 StepByStep(2)
    UI线程同步
    每日见闻(一)
    作业调度框架 Quartz.NET 2.0 StepByStep
    基础算法(ACwing)
  • 原文地址:https://www.cnblogs.com/argor/p/7910935.html
Copyright © 2011-2022 走看看