expect实现ssh自动登录 



 


  1. #!/usr/local/bin/expect
  2. set PASSWD [lindex $argv 1]
  3. set IP [lindex $argv 0]
  4. set CMD [lindex $argv 2]
  5. spawn ssh $IP $CMD
  6. expect "(yes/no)?" {
  7.         send "yes\r"
  8.         expect "password:"
  9.         send "$PASSWD\r"
  10. } "password:" {send "$PASSWD\r"} "*host " {exit 1}
  11. expect eof