expect
#!/usr/bin/expect -f
set ipaddr "192.168.5.4"
set passwd "123qwe"
set timeout 30
spawn ssh root@$ipaddr
expect {
"yes/no" { send "yes\r"; exp_continue }
"password: " { send "$passwd\r" }
}
expect "*# "
send "ls\r"
send "exit\r"
expect eof
exit