expect嵌套shell循環


#!/bin/bash

Detailtxt="test.txt"
while read line

do

   dest=`echo $line|awk '{print $1}'`
   ip=`echo $line|awk '{print $2}'`
   /usr/bin/expect <<-EOF
   spawn scp /etc/hosts root@ip:$dest
   expect { 
"yes/no" {send "yes\r";exp_continue}
"password:" { send "密碼\n" }
}

   expect "*#"
EOF


done < $Detailtxt

其中test.txt格式如下

/tmp ip地址


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM