expect ssh首次登录自动判断(yes/no)?

v-lhb-prx01:/root/sbin# sh ./expect.sh 
spawn ssh root@192.168.32.16
The authenticity of host '192.168.32.16 (192.168.32.16)' can't be established.
RSA key fingerprint is da:3a:61:09:e4:f6:46:d7:01:08:1a:6c:b9:41:e8:4c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.32.16' (RSA) to the list of known hosts.
root@192.168.32.16's password: 
Last login: Wed May 27 09:37:32 2015 from 192.168.33.107

v-dev-redis02:/root# df -h
Filesystem                Size  Used Avail Use% Mounted on
/dev/mapper/vg00-lv_root  7.7G  5.6G  1.8G  77% /
tmpfs                     499M     0  499M   0% /dev/shm
/dev/sda1                 194M   29M  155M  16% /boot
v-dev-redis02:/root# exit
logout
Connection to 192.168.32.16 closed.



-----------------------------------------------------------------------------------

expect {
    "(yes/no)?" {
        send "yes
"
        expect "password:"
        send "$passwd
"
    }
        "password:" {
        send "$passwd
"
    }
 }
# 下面测试是否登录到 
expect "#" 
send "df -h
"
send "exit
"
expect eof

原文地址:https://www.cnblogs.com/hzcya1995/p/13351655.html