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地址

posted @ 2018-11-16 10:35  梦轻尘  阅读(2193)  评论(1编辑  收藏  举报