linux expect
1.首先确定是否安装expect
/home/root> which expect /usr/bin/expect
如果没有安装,先安装一下
安装方法: 请参考 http://www.cnblogs.com/daojian/archive/2012/10/10/2718390.html
your script:
#!/usr/bin/expect -f
#!/usr/bin/expect -f set ip 16.235.158.92 set password redhat06 set timeout 5 spawn ssh sqdev8@$ip expect { "*yes/no" { send "yes\r"; exp_continue} "*password:" { send "$password\r" } } expect "#*" send "echo \$USER\r" expect { "*sqdev*" { send "hostname\r" } } exec sleep 2 send "exit\r" expect eof
转载请注明出处:http://www.cnblogs.com/tobecrazy/