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地址
天天向上,空杯心态。