ansible 远程执行脚本和执行任务计划
2017-03-06 14:43
323 查看
一 远程执行脚本
l首先创建一个shell脚本
lvim /tmp/test.sh //加入内容
l#!/bin/bash
lecho `date` > /tmp/ansible_test.txt
l然后把该脚本分发到各个机器上
ansible ip -m copy -a "src=/tmp/test.sh dest=/tmp/test.sh mode=0755"
l最后是批量执行该shell脚本
ansible ip -m shell -a "/tmp/test.sh"
lshell模块,还支持远程执行命令并且带管道
ansible testhost -m shell -a "cat /etc/passwd|wc -l "
最后去远程机器上面看/tmp目录下是否有test.sh这个文件即可
二 任务计划设置
1)添加任务计划
lansible ip -m cron -a "name='test cron' job='/bin/touch /tmp/1212.txt' weekday=6“
##每周六在/tmp/目录下面创建1212.txt文件
实例:
若要删除该cron 只需要加一个字段 state=absent
ansible ip -m cron -a "name='test cron' state=absent" ##删除任务计划
例子
l其他的时间表示:分钟 minute 小时 hour 日期 day 月份 month
l首先创建一个shell脚本
lvim /tmp/test.sh //加入内容
l#!/bin/bash
lecho `date` > /tmp/ansible_test.txt
l然后把该脚本分发到各个机器上
ansible ip -m copy -a "src=/tmp/test.sh dest=/tmp/test.sh mode=0755"
l最后是批量执行该shell脚本
ansible ip -m shell -a "/tmp/test.sh"
lshell模块,还支持远程执行命令并且带管道
ansible testhost -m shell -a "cat /etc/passwd|wc -l "
最后去远程机器上面看/tmp目录下是否有test.sh这个文件即可
二 任务计划设置
1)添加任务计划
lansible ip -m cron -a "name='test cron' job='/bin/touch /tmp/1212.txt' weekday=6“
##每周六在/tmp/目录下面创建1212.txt文件
实例:
[root@web9 tmp]# ansible 192.168.253.131 -m cron -a "name='test cron' job='/bin/touch /tmp/1212.txt' weekday=6" 192.168.253.131 | success >> { "changed": true, "jobs": [ "test cron" ] }2) 删除任务计划
若要删除该cron 只需要加一个字段 state=absent
ansible ip -m cron -a "name='test cron' state=absent" ##删除任务计划
例子
[root@web9 tmp]# ansible 192.168.253.131 -m cron -a "name='test cron' state=absent" 192.168.253.131 | success >> { "changed": true, "jobs": [] }最后在客户端里面查看 crontab -l 会被删除
l其他的时间表示:分钟 minute 小时 hour 日期 day 月份 month
相关文章推荐
- PHP计划任务:如何使用Linux的Crontab执行PHP脚本
- [BAT]批处理脚本双击可运行,但在定时计划任务中无法执行(当前工作路径不对导致的)
- PHP计划任务:如何使用Linux的Crontab执行PHP脚本
- PHP计划任务:如何使用Linux的Crontab执行PHP脚本
- PHP计划任务:如何使用Linux的Crontab执行PHP脚本
- win7计划任务定时执行PHP脚本设置图解
- 设定Windows计划任务定期执行PowerShell脚本
- PHP计划任务:如何使用Linux的Crontab执行PHP脚本
- PHP计划任务:如何使用Linux的Crontab执行PHP脚本
- 利用win7计划任务本地执行php脚本
- Windows 添加计划任务 每隔一定时间执行指定批处理脚本
- win7计划任务定时执行PHP脚本设置图解
- 远程推送脚本,创建任务计划
- Windows 添加计划任务 每隔一定时间执行指定批处理脚本
- PHP计划任务:如何使用Linux的Crontab执行PHP脚本
- PHP计划任务:如何使用Linux的Crontab执行PHP脚本
- 如何用计划任务执行powershell脚本
- 设定Windows计划任务定期执行PowerShell脚本
- 远程执行windows上的计划任务
- 【转】PHP计划任务:如何使用Linux的Crontab执行PHP脚本