和工作有关的ansible 的应用 + disk usage 监控脚本

1: 一台server 监控很多server 的 disk usage 的脚本:

  先把 script 脚本scp 传递到client server: 

 cat /root/david/check_disk.sh

#!/bin/sh
df -H | grep -vE '^Filesystem' | awk '{ print $5 " " $6 }' | while read output;
do
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
  if [ $usep -ge 20 ]; then
    echo " \"$partition ($usep%)\" on $(hostname) as on $(date)" 
  fi
done
 

然后在 管理机器上run: ansible all -m shell -a "/root/david/check_disk.sh"  既可以看到哪些server 的usage 满啦。 然后在linux 安装sendmail: yum install sendmail, then 起 sendmail 服务:service sendmail restart.

然后要sendmail service 是否开机启动: (如果是disable, 可以通过: systemctl enable sendmail 来设置一下)

[root@oc2246430752 scripts]# systemctl list-unit-files | grep -i sendmail
sendmail.service                                                        enabled 

  把上面的输出结果发邮件:  (mail_notice.sh  可以定义在cron 里面)

root@oc2246430752 scripts]# cat mail_notice.sh 
ansible all -m shell -a "/root/david/check_disk.sh" > /tool/scripts/test_script_result.txt
cat /tool/script/test_script_result.txt | mail -s "warning disk usage" XXX@XX.com

cron 里面定义:0 */1 * * * mail_notice.sh     # 每1小时执行一下mail_notice.sh 的脚本

 

2: check 大量server 是否还活着, ping 的话,机器可能会reboot, 所以用uptime 来检测:

ansible all -m command -a uptime

3: 有的客户需要取很多sever 的audit log: uslog / or syslog, 也可以通过下面命令:

ansible all -m fetch -a "src=/home/sheng/sulog dest=/tmp/"

4: 当然还有在大量机器上create user / group 的应用:

ansible all -m command -a "useradd test"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shenghuiping2001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值