expect自动输入密码

#!/usr/bin/expect


set password "vision"

set passwor "vision"


spawn ssh root@192.168.3.8


set timeout 300


expect {


"*yes/no" { send "yes\r"; exp_continue}


"*password:" { send "$password\r" }


}

expect "]*"

send "df -Th >>/tmp/df.txt\r"

expect "]*"


expect "]*"

send "exit\r"

那怎么把在远端机文件自动传回来呢?



下面是expect for循环:

#!/usr/bin/expect


set timeout -1


foreach i { 192.168.3.113 } {

spawn ssh -i  /home/lee/.ssh/id_rsa_expect  root@$i "free -m >/root/${i}_memory.txt"

expect  "yes/no"

send "yes\r"

interact

sleep 1

spawn scp -i  /home/lee/.ssh/id_rsa_expect  $i:/root/${i}_memory.txt  /root/


expect eof

sleep 2

}

















本文转自chenzudao51CTO博客,原文链接:http://blog.51cto.com/victor2016/1914723 ,如需转载请自行联系原作者


上一篇:Docker Compose自建NuGet服务器


下一篇:SpringBoot怎样整合RabbitMQ? | 带你读《SpringBoot实战教程》之三十六