#!/bin/sh
#在目标机器上设置sudo特殊权限rsync,使用ssh连接后直接执行sudo命令进行推送
#将执行结果写入文档,当错误日志不为空时,将触发邮箱服务并清空原有服务,前提开启邮箱服务
. /etc/init.d/functions
[ $# -eq 2 ]||{
echo "USAGE: $0 FILENAME1 FILENAME2"
exit 1
}
for n in 8 9
do
#r复制目录,p保持属性
scp -rp $1 skyboy@192.168.137.${n}:~ &>/dev/null
echo ==========================192.168.137.${n}=============================
ssh -t skyboy@192.168.137.$n sudo rsync $1 $2 &>/dev/null
[ $? -eq 0 ]&&{
action "$0 192.168.137.$n is ok" /bin/true
touch /var/log/ok.log &&\
echo "$0 192.168.137.$n is ok" >>/var/log/ok.log
}||{
action "$0 192.168.137.$n is fail" /bin/false
touch /var/log/fail.log &&\
echo "$0 192.168.137.$n is fail" >>/var/log/fail.log
}
done
[ -s "/var/log/fail.log" ]||{
mail -s "$(date +%F_%T) title" 495031718@qq.com </var/log/fail.log
}
>/var/log/fail.log
>/var/log/ok.log
本文出自 “神奇的海螺” 博客,谢绝转载!
原文地址:http://bilishell.blog.51cto.com/11756401/1841275