作者:手机用户2502895517 | 来源:互联网 | 2023-08-26 10:20
#!binbash########################################################################## File Name : rsync_nobody.sh# 
#!/bin/bash
#########################################################################
# File Name : rsync_nobody.sh
# Author : gongy
# Mail : 458026734@qq.com
# Created time : 2016-06-29 09:58:53
# Last modified : 2016-06-29 09:58:53
# Description : rsync nobodyfile to remote machine.
#########################################################################
#Loading system function library.
source /etc/init.d/functions
set -e
#defined variable.
DATE=`date +%Y%m%d`
TIME=`date '+%F %H:%M:%S'`
MYSQL_USER=""
MYSQL_PASSWD=""
MYSQL_ADDRESS=""
EXEC_LOG="/app/control_crontab/log/exec_$DATE.log"
DATA_LOG="/app/control_crontab/log/${IP}_data_$DATE.log"
SOURCE_FILE="/app/control_crontab/cron/nobody/"
DIST_FILE="/var/spool/cron"
#get ip list.
ip=(
`mysql -uroot -e "use db_devops;select IP from tbl_all_ip"|sed '1d'`
)
function judge(){
if [ $? -eq 0 ];then
action "$TIME-${ip[$i]}-rsync nobody file" /bin/true
else
action "$TIME-${ip[$i]}-rsync nobody file" /bin/false
#MSG="${ip[$i]}更新nobody失败"
#curl "http://alarm.51.com/alarm/index.php?type=1&gid=99&msg=${MSG}" &>/dev/null
fi
}
function rsync_all(){
#rsync all nobody file.
for ((i=0;i<${#ip[*]};i++))
do
#rsync同步nobody到RMOTE主机,更新文件.
rsync -az ${SOURCE_FILE}/nobody-${ip[$i]} ${ip[$i]}:${DIST_FILE}/nobody &> /dev/null
judge
done
}
#echo "===========================================================================" >> ${EXEC_LOG}
function rsync_more(){
#IP=`cat ip_file`
for IP in `cat ip_file`
do
rsync -az ${SOURCE_FILE}/nobody-$IP $IP:${DIST_FILE}/nobody &> /dev/null
result
done
}
function result(){
if [ $? == 0 ];then
echo "$TIME-$IP-rsync nobody file....................................................[OK]"
else
echo "$TIME-$IP-rsync nobody file....................................................[FAILED]"
fi
sleep 1
}
read -p "Please enter your chose all/one:" input
case $input in
"all")
rsync_all
;;
"one")
read -p "Please enter the file:" ip_file
rsync_more
;;
*)
exit
;;
esac