標籤: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)