#!/bin/bash##########################################################################FileName:rsync_nobody.sh#Author:gongy#Mail:458026734@qq.com#Createdtime:2016-06-2909:58:53#Lastmodified:2016-06-2909:58:53#Description:rsyncnobodyfiletoremotemachine.##########################################################################Loadingsystemfunctionlibrary.source/etc/init.d/functionsset-e#definedvariable.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"#getiplist.ip=(`mysql-uroot-e"usedb_devops;selectIPfromtbl_all_ip"|sed'1d'`)functionjudge(){if[$?-eq0];thenaction"$TIME-${ip[$i]}-rsyncnobodyfile"/bin/trueelseaction"$TIME-${ip[$i]}-rsyncnobodyfile"/bin/false#MSG="${ip[$i]}更新nobody失败"#curl"http://alarm.51.com/alarm/index.php?type=1&gid=99&msg=${MSG}"&>/dev/nullfi}functionrsync_all(){#rsyncallnobodyfile.for((i=0;i<${#ip[*]};i++))do#rsync同步nobody到RMOTE主机,更新文件.rsync-az${SOURCE_FILE}/nobody-${ip[$i]}${ip[$i]}:${DIST_FILE}/nobody&>/dev/nulljudgedone}#echo"===========================================================================">>${EXEC_LOG}functionrsync_more(){#IP=`catip_file`forIPin`catip_file`dorsync-az${SOURCE_FILE}/nobody-$IP$IP:${DIST_FILE}/nobody&>/dev/nullresultdone}functionresult(){if[$?==0];thenecho"$TIME-$IP-rsyncnobodyfile....................................................[OK]"elseecho"$TIME-$IP-rsyncnobodyfile....................................................[FAILED]"fisleep1}read-p"Pleaseenteryourchoseall/one:"inputcase$inputin"all")rsync_all;;"one")read-p"Pleaseenterthefile:"ip_filersync_more;;*)exit;;esac