Thursday, September 8, 2011

使用expect自动登录SSH脚本

[cc lang="bash"]#!/usr/bin/expect -f
set server [lindex $argv 0]

trap {
set rows [stty rows]
set cols [stty columns]
stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCH

switch -- $server \
"mail" {
spawn ssh -p 51 root@mail
expect "password:"
send "A)Q11dDuh^.\n"
interact
} "win1" {
exec rdesktop -u administrator -p "aU\$B_C%K" 192.168.111.3
} default {
puts "input a server name"
}

expect eof[/cc]

No comments:

Post a Comment