伺服器群秒層級檔案同步(ssh+SHELL)

來源:互聯網
上載者:User

標籤:conf   bsp   檔案   oca   custom   .sh   success   value   技術   

1.介紹

\

2.商務服務器遠程更新瀏覽伺服器檔案的指令碼

#!/bin/bashoperate=$1ip=$2conf_file="/var/www/html/test/ip_list"file_chsum="/var/www/html/test/cksvalue"file_ser="10.60.10.62"cksum(){  ssh ${file_ser} "cksum ${conf_file}|awk ‘{print\$1}‘ > ${file_chsum}"  if [ $? -ne 0 ];then    #產生cksum值失敗    echo "10005"  fi}if [[ ! $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]];then  #IP不合法  echo "10003";  exit 1;fiif [[ "${operate}" == "add" ]];then  ips=`ssh ${file_ser} "cat $conf_file|grep ${ip}/32|wc -l"`  if [ ${ips} -eq 0 ];then    ssh ${file_ser} "echo "${ip}/32" >> $conf_file"    if [ $? -eq 0 ];then      cksum      #添加IP成功      echo "10000"      exit 0;    else      #添加IP失敗      echo "10001"      exit 1;    fi  else    #添加IP成功(IP已存在)    echo "10000";    exit 0;  fielif [[ "${operate}" == "del" ]];then  ssh ${file_ser} "sed -i ‘/${ip}\/32/d‘ $conf_file"  if [ $? -eq 0 ];then    cksum    #刪除IP成功    echo "10000"    exit 0;  else    #刪除IP失敗    echo "10002"    exit 1;  fielse   #參數1($1)不合法  echo "10004"  exit 1;fi

3.瀏覽伺服器採用http的方式提供設定檔和cksum值的瀏覽和下載

4.VPS主機群每隔30校正一次設定檔的cksum值來保持設定檔的最新狀態

* * * * * sleep 10 && sh /tmp/sync_customIP.sh* * * * * sleep 40 && sh /tmp/sync_customIP.sh
#!/bin/bashconf_file_url="http://10.60.10.62:8060/test/ip_list"cksum_url="http://10.60.10.62:8060/test/cksvalue"local_conf_file="/tmp/ip_list"time=`date`log="/tmp/sync_customIP.log"get_cksum() {  remote_cksum=`curl -s "${cksum_url}"`  local_cksum=`cksum ${local_conf_file}|awk ‘{print\$1}‘`}sync_file() {  cat ${local_conf_file} > /tmp/.tmp_ip.txt  wget -q  ${conf_file_url} -O ${local_conf_file};}get_cksumif [[ "$remote_cksum" != "$local_cksum" ]];then  sync_file  get_cksum  if [[ "$remote_cksum" != "$local_cksum" ]];then    cat /tmp/.tmp_ip.txt > ${local_conf_file}    echo "${time} sync fail.." >> $log  else    echo "${time} sync  success.." >> $log  fielse  echo "${time} there are no need to sync.. ">> $logfilog_count=`cat $log |wc -l`if [ $log_count -gt 2000 ];then  sed -i ‘1,1000d‘ $logfi

 

伺服器群秒層級檔案同步(ssh+SHELL)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.