#!/bin/bash passwd='nihao23d23d' /usr/bin/expect << _EOF spawn ssh -p22 flli@10.189.103.12 expect { "Are you sure you want to continue connecting (yes/no)?" { send "yes\r" } "*password:" { send "${passwd}\r" } "Permission denied, please try again." { exit } "Connection refused" { exit } timeout { exit } eof { exit } } expect "*$" send "hostname\r" expect "*$" send "exit\r" expect eof _EOF
===================来自一泽涟漪的博客,转载请标明出处 www.cnblogs.com/ilifeilong===================