#!/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
集中化管理crontab
原创
©著作权归作者所有:来自51CTO博客作者gongxiaoyi的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
用户集中管理
第一篇,写来玩玩
linux