• 欢迎访问蜷缩的蜗牛博客 蜷缩的蜗牛
  • 微信搜索: 蜷缩的蜗牛 | 联系站长 kbsonlong@qq.com
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Saltstack –crontab定时任务管理

Saltstack 蜷缩的蜗牛 2年前 (2017-02-19) 173次浏览 已收录 0个评论

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:

蜷缩的蜗牛 , 版权所有丨如未注明 , 均为原创丨 转载请注明Saltstack –crontab 定时任务管理
喜欢 (1)
[]
分享 (0)

您必须 登录 才能发表评论!