Linux自动化工具之Ansible实现任务计划
2020-02-21自动化运维90root268°c
A+ A-1、比如说周六去执行
[[email protected] ~]# ansible testhosts -m cron -a "name=test_cron job='/bin/bash /usr/local/sbin/1.sh' weekday=6" 101.200.148.30 | SUCCESS => { "changed": true, "envs": [], "jobs": [ "test_cron" ] } 127.0.0.1 | SUCCESS => { "changed": true, "envs": [], "jobs": [ "test_cron" ] }
Ansible testhosts -m 组
cron -a “name=test_cron 给cron定义一个name,以后方便删除。
job=’/bin/bash /usr/local/sbin/1.sh’ 具体的任务
weekday=6” 周六的时候去执行
2、检查有没有成功
[[email protected] ~]# crontab -l #Ansible: test_cron * * * * 6 /bin/bash /usr/local/sbin/1.sh
3、若想删除只需添加一个字段 state=absent
[[email protected] ~]# ansible testhosts -m cron -a "name=test_cron state=absent" 101.200.148.30 | SUCCESS => { "changed": true, "envs": [], "jobs": [] } 127.0.0.1 | SUCCESS => { "changed": true, "envs": [], "jobs": [] }
4、其他时间表示:分钟minute 小时hour 日期day 月份month
[[email protected] ~]# ansible testhosts -m cron -a "name=test_cron job='/bin/bash /usr/local/sbin/1.sh' day='1,5,10' weekday=6" 101.200.148.30 | SUCCESS => { "changed": true, "envs": [], "jobs": [ "test_cron" ] } 127.0.0.1 | SUCCESS => { "changed": true, "envs": [], "jobs": [ "test_cron" ] }
5、查看有没有执行成功
[[email protected] ~]# crontab -l #Ansible: test_cron * * 1,5,10 * 6 /bin/bash /usr/local/sbin/1.sh