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  

相关文章:

  • 2022-12-23
  • 2021-12-17
  • 2022-01-08
  • 2021-08-22
  • 2021-11-30
  • 2022-01-07
  • 2022-01-03
猜你喜欢
  • 2022-03-07
  • 2022-12-23
  • 2021-10-15
  • 2021-08-23
  • 2022-01-25
相关资源
相似解决方案