#!/bin/bash # 將代碼和腳本傳送至worker節點 # 改變當前工做目錄 cd ${AMAZONCRAWLER_HOME} #讀取worker節點ip列表 i=0 while read line1 do #去除空格 line1=`echo $line1 | sed s/[[:space:]]//g` #若爲空則忽略本行 if [ "$line1"x = x ]; then continue fi #如果註釋行 忽略 startChar=${line1:0:1} if [ "$startChar"x = "#"x ]; then continue fi #存儲至worker_ips數組 worker_ips[$i]=$line1 ((i++)) done < ./conf/system/worker #讀取service列表 i=0 while read line1 do #去除空格 line1=`echo $line1 | sed s/[[:space:]]//g` #若爲空則忽略本行 if [ "$line1"x = x ]; then continue fi #如果註釋行 忽略 startChar=${line1:0:1} if [ "$startChar"x = "#"x ]; then continue fi #存儲至services數組 services[$i]=$line1 ((i++)) done < ./conf/system/services worker_ips[0]='59.77.132.28' for worker_ip in ${worker_ips[*]} do echo ------------------------------------------ echo copy to ${worker_ip} ssh -p 22 fzuir@${worker_ip} "(. /etc/profile;mkdir -p ${AMAZONCRAWLER_HOME}/conf/system)" scp conf/system/configuration.properties conf/system/chromedriver fzuir@${worker_ip}:${AMAZONCRAWLER_HOME}/conf/system for service in ${services[*]} do ssh -p 22 fzuir@${worker_ip} "(. /etc/profile;mkdir -p ${AMAZONCRAWLER_HOME}/SharedStorage/${service})" scp -r SharedStorage/${service}/*.jar fzuir@${worker_ip}:${AMAZONCRAWLER_HOME}/SharedStorage/${service} scp -r SharedStorage/${service}/*.sh fzuir@${worker_ip}:${AMAZONCRAWLER_HOME}/SharedStorage/${service} done scp -r SharedStorage/*.sh fzuir@${worker_ip}:${AMAZONCRAWLER_HOME}/SharedStorage done
#!/bin/bash #變量定義 ip_array=("59.77.233.195" "59.77.233.197" "59.77.233.196" "218.193.126.186" "218.193.126.188" "218.193.126.191" "218.193.126.192") user="fzuir" cmd="sudo date -s '2016-9-24 16:34:00'" port="22" #本地經過ssh執行遠程服務器的腳本 for ip in ${ip_array[*]} do ssh -t -p $port $user@$ip $cmd done