yum install expect -y


#!/usr/bin/expect -f  
 set ip 192.168.1.251
 set password edcvfr42w
 set timeout 5
 spawn ssh root@$ip
 expect {
 "*password:" { send "$password\r" }
 }
 expect "#*"  
 send "pwd\r"
# send  "exit\r"  
# expect eof  
interact

~