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