argor

   :: 首页  :: 新随笔  :: 联系 ::  :: 管理

 

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

 

posted on 2017-11-28 17:04  argor  阅读(769)  评论(0)    收藏  举报