ssh 遠程執行命令操作

target_ips=(
'10.15.241.21'
'10.15.241.22'
'10.15.241.23'
'10.15.241.24'
'10.15.241.25'
);

function setupOneTarget()
{
   index=$1;
   current_ip=${target_ips[$index]};
   echo try to setup current_ip: $current_ip;

   echo step 1: copy files
   scp -i /root/.ssh/cloud-multimedia.key libevent-2.0.21-stable.tar.gz root@$current_ip:/root/
   scp -i /root/.ssh/cloud-multimedia.key turn.tar.gz root@$current_ip:/root/
   scp -i /root/.ssh/cloud-multimedia.key turnserver.conf root@$current_ip:/etc/

   echo step 2: unzip file
   ssh -i /root/.ssh/cloud-multimedia.key -p 22 root@$current_ip 'cd /root; tar xvf libevent-2.0.21-stable.tar.gz'
   ssh -i /root/.ssh/cloud-multimedia.key -p 22 root@$current_ip 'cd /root; tar xvf turn.tar.gz'

   echo step3: compile and install 
   ssh -i /root/.ssh/cloud-multimedia.key -p 22 root@$current_ip 'yum -y install openssl-devel.x86_64'
   ssh -i /root/.ssh/cloud-multimedia.key -p 22 root@$current_ip 'cd /root/libevent-2.0.21-stable/; ./configure --enable-openssl=yes; make -j8; make install'
   ssh -i /root/.ssh/cloud-multimedia.key -p 22 root@$current_ip 'cd /root/turn/; ./configure; make -j8; make install'

   echo setup current_ip: $current_ip done;
}


function setupTarget() 
{
  for((i = 0; i < $1; i++))
    do setupOneTarget $i;
    done;
}
發佈了43 篇原創文章 · 獲贊 19 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章