auto ssh other linux host via expect

来源:互联网 发布:linux eth1 改为eth0 编辑:程序博客网 时间:2024/05/21 15:46

# cat /usr/bin/juli-auto-ssh-193.sh

#!/usr/bin/expect## Access CLIset loginUser "root"set loginPassword "911911911"set mgmtServerAddress "219.224.167.193"spawn ssh -l $loginUser $mgmtServerAddress -p 22 -Xset timeout  2expect "Are you sure you want to continue connecting (yes/no)? " {send "yes\r"}##interact with SSHset timeout 120expect "vrlab@219.224.167.193's password:" {send "$loginPassword\r"}interact

===============================

ref: http://www.thegeekstuff.com/2010/10/expect-examples/


SSH Login into Another Machine

The example expect program shown below automates the ssh login from one machine to another machine.

#!/usr/bin/expectset timeout 20set ip [lindex $argv 0]set user [lindex $argv 1]set password [lindex $argv 2]spawn ssh "$user\@$ip"expect "Password:"send "$password\r";interact

Execute the above expect program as shown below.

guest@host1 $ ./ssh.exp 192.168.1.2 root passwordspawn ssh root@192.168.1.2Password:Last login: Sat Oct  9 04:11:35 2010 from host1.geetkstuff.comroot@host2 #

0 0
原创粉丝点击