#!/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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。