#!/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
}