前言:在日常变更过程中,变更前会注释某些定时任务(比如巡检告警等),变更完成后需恢复,有时变更操作的服务器很多,对应需要注释的crontab也很多且不相同,本文通过分发平台执行对应脚本批量实现crontab的注释和解注释功能。
环境说明:
主机名 | 操作系统版本 | ip | 用户名 | 备注 |
---|---|---|---|---|
ansible | Centos 7.6.1810 | 172.27.34.51 | crontab测试服务器01 | |
ansible-awx | Centos 7.6.1810 | 172.27.34.50 | crontab测试服务器02 |
一、crontab测试环境准备
1.主机ansible环境准备
[user_test@ansible ~]$ echo $HOME/home/user_test[user_test@ansible ~]$ crontab -l0 0 * * * /home/user_test/bin/date > /dev/null0 0 * * * $HOME/bin/date > /dev/null0 0 * * * date > /dev/null* * * * * df -h > /tmp/df.txt0 0 * * * $HOME/bin/pwd_test > /dev/null[user_test@ansible ~]$ pwd/home/user_test[user_test@ansible ~]$ ll总用量 8drwxrwxr-x 2 user_test user_test 6 9月 8 11:22 bin-rwxrw-r-- 1 user_test user_test 309 9月 8 11:01 crontab2.sh-rwxrw-r-- 1 user_test user_test 303 9月 8 10:59 crontab.sh[user_test@ansible ~]$ cd bin[user_test@ansible bin]$ ll总用量 0[user_test@ansible bin]$ ln -s /usr/bin/date date[user_test@ansible bin]$ ln -s /usr/bin/pwd pwd_test[user_test@ansible bin]$ ll总用量 0lrwxrwxrwx 1 user_test user_test 13 9月 8 11:23 date -> /usr/bin/datelrwxrw