当前位置:首页 > 站长资讯 > 建站
Saltstack --crontab定时任务管理
时间:2017-01-03 16:38:04   来源:炎风狼   编辑:涛涛   点击:  

A-A+

1、查看minion端定时任务

语法:

salt.modules.cron.list_tab(user)

salt.modules.cron.ls(user)

以上两种用法实际上返回相同结果

 

# salt 192.168.62.158 cron.list_tab root  
192.168.62.158:
    ----------
    crons:
        |_
          ----------
          cmd:
              sh /data/PRG/tengine/logs/tengine_log_cut.sh
          comment:
          commented:
              False
          daymonth:
              *
          dayweek:
              *
          hour:
              0
          identifier:
              sh /data/PRG/tengine/logs/tengine_log_cut.sh
          minute:
              0
          month:
              *
        |_
          ----------
          cmd:
              ntpdate 192.168.62.169
          comment:
              None
          commented:
              False
          daymonth:
              *
          dayweek:
              *
          hour:
              *
          identifier:
              None
          minute:
              */5
          month:
              *
    env:
    pre:
        - #*/5 * * * * /var/process.sh >/dev/null 2>&1
    special:

 

# salt 192.168.62.158 cron.ls root
192.168.62.158:
    ----------
    crons:
        |_
          ----------
          cmd:
              sh /data/PRG/tengine/logs/tengine_log_cut.sh
          comment:
          commented:
              False
          daymonth:
              *
          dayweek:
              *
          hour:
              0
          identifier:
              sh /data/PRG/tengine/logs/tengine_log_cut.sh
          minute:
              0
          month:
              *
        |_
          ----------
          cmd:
              ntpdate 192.168.62.169
          comment:
              None
          commented:
              False
          daymonth:
              *
          dayweek:
              *
          hour:
              *
          identifier:
              None
          minute:
              */5
          month:
              *
    env:
    pre:
        - #*/5 * * * * /var/process.sh >/dev/null 2>&1
    special:

 

2、添加定时任务

语法:

salt.modules.cron.set_job(user, minute, hour, daymonth, month, dayweek, cmd, commented=False,comment=None, identifier=None)

 

#salt 192.168.62.158 cron.set_job root   '*/1' '*' '*' '*' '*'  'cd /usr/local/gse/; ./cron_gse.sh 1>/dev/null 2>&1' 
192.168.62.158:
    new

 

查看是否添加成功

# salt 192.168.62.158 cron.ls root 
192.168.62.158:
    ----------
    crons:
        |_
          ----------
          cmd:
              sh /data/PRG/tengine/logs/tengine_log_cut.sh
          comment:
          commented:
              False
          daymonth:
              *
          dayweek:
              *
          hour:
              0
          identifier:
              sh /data/PRG/tengine/logs/tengine_log_cut.sh
          minute:
              0
          month:
              *
        |_
          ----------
          cmd:
              ntpdate 192.168.62.169
          comment:
              None
          commented:
              False
          daymonth:
              *
          dayweek:
              *
          hour:
              *
          identifier:
              None
          minute:
              */5
          month:
              *
        |_
          ----------
          cmd:
              cd /usr/local/gse/; ./cron_gse.sh 1>/dev/null 2>&1
          comment:
              None
          commented:
              False
          daymonth:
              *
          dayweek:
              *
          hour:
              *
          identifier:
              None
          minute:
              */1
          month:
              *
    env:
    pre:
        - #*/5 * * * * /var/process.sh >/dev/null 2>&1
    special:

 

 

3、删除定时任务

语法:

salt.modules.cron.rm_job(user, cmd, minute=None, hour=None, daymonth=None, month=None, day-week=None, identifier=None)

如果不清楚删除cmd ,可以先使用查看命令(cron.ls)查看需要删除的cmd

# salt 192.168.62.158 cron.rm_job root 'cd /usr/local/gse/; ./cron_gse.sh 1>/dev/null 2>&1'            
192.168.62.158:
    removed

 

查看是否删除

# salt 192.168.62.158 cron.ls root 
192.168.62.158:
    ----------
    crons:
        |_
          ----------
          cmd:
              sh /data/PRG/tengine/logs/tengine_log_cut.sh
          comment:
          commented:
              False
          daymonth:
              *
          dayweek:
              *
          hour:
              0
          identifier:
              sh /data/PRG/tengine/logs/tengine_log_cut.sh
          minute:
              0
          month:
              *
        |_
          ----------
          cmd:
              ntpdate 192.168.62.169
          comment:
              None
          commented:
              False
          daymonth:
              *
          dayweek:
              *
          hour:
              *
          identifier:
              None
          minute:
              */5
          month:
              *
    env:
    pre:
        - #*/5 * * * * /var/process.sh >/dev/null 2>&1
    special:
  踩 1
分享到:
精彩评论
看过本文的人还看过
专栏
  • 240期
    一个文化艺术垂直电子商务网站。
  • 240期
    一个文化艺术垂直电子商务网站。