#!/bin/bash
WEBTEMP_PATH="webtemp"
DATE=`/bin/date +%Y%m%d_%H_%M:%S`

FILE_DIR=/webtemp
for FILE_SUBDIR in  ${FILE_DIR}/web171 ${FILE_DIR}/web208 ${FILE_DIR}/web181
do

     case $(echo $FILE_SUBDIR |  cut -d "/" -f 3)  in
      "web171")
      IP="192.168.1.171"
      LOG="/webtemp/web171.log"   
      ;;
      "web208")
      IP="192.168.1.208"
      LOG="/webtemp/web208.log"
      ;;
      "web181")
      IP="192.168.1.181"
      LOG="/webtemp/web181.log"
      ;;
       *)
      exit
      ;;
     esac

     #for  FILE_PATH in $(ls ${FILE_SUBDIR}/upload_list*)
     for  FILE_PATH in $(ls ${FILE_SUBDIR}/upload_* 2> /dev/null )   
  do

#    echo $FILE_PATH
          if ! [ -f $(ls ${FILE_PATH} 2> /dev/null) ];then
        echo -e "\033[31m ${FILE_SUBDIR} $FILE_PATH does not Exist \033[0m"
        break
        fi   

    echo -e ======================================= >> $LOG
    echo -e $FILE_PATH >> $LOG
    echo -e "$DATE\t\n$(cat  $FILE_PATH)\t" >> $LOG

###########
sed -i '/^[ \t]*$/d' $FILE_PATH

                  for LIST in $(cat $FILE_PATH)
                do
                   if [ -f ${LIST} ] || [ -d ${LIST} ]; then
         for host in $IP
         do
    #if [ "$(echo $LIST | awk 'BEGIN {FS="/"} {print $2}')" == "var" ];then   
                  if echo $LIST | grep -q  ^\/var/www.* ;then
            echo -e "\033[33m Sending $LIST files to $IP  \033[0m"
                                if ! ssh -p 22 test01@$IP test -d $LIST;then
                                        if ssh -p 22 test01@$IP test -x $LIST;then
                                        echo -e "\033[31m Waring!! Your File $LIST have Executive \033[0m"
                    echo -e "Waring!! Your File $LIST have Executive\t" >> $LOG
                                        sleep 3s
                    fi
                ssh -p 22 test01@$IP mkdir -p $WEBTEMP_PATH/$DATE
                ssh -p 22 test01@$IP cp -a $LIST ~/$WEBTEMP_PATH/$DATE
                rsync -avlR --password-file=/etc/rsyncd.secrets --log-file=/var/log/rsync_web_$IP.log ${LIST} root@$IP::Test-196
                rsync -avlR --password-file=/etc/rsyncd.secrets ${FILE_PATH} root@$IP::Test-196
                ssh -p 22 root@$IP /home/ryan/work_sh/unison/unison_web   
                fi
        else echo -e  "\033[31m Destination $LIST not in /var/www \033[0m"
             echo -e  "Destination $LIST not in /var/www"
        fi
         done
      else echo -e  "\033[31m File or Folder does not Exist :$LIST \033[0m"
           echo -e  "File or Folder does not Exist :$LIST"   
      fi
    done
#    echo -e "\033[33m ===================== done done done ======================== \033[0m"

cd ${FILE_SUBDIR}
rm -f $FILE_PATH
echo -e "\033[31m ${FILE_SUBDIR} $FILE_PATH already Killed \033[0m"
echo -e "\033[33m ===================== done done done ======================== \033[0m"

       done

done

neo2124 發表在 痞客邦 PIXNET 留言(0) 人氣()