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" [email protected]
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"