Skip to content

Instantly share code, notes, and snippets.

@dongweiming
Created November 22, 2013 02:16
Show Gist options
  • Save dongweiming/7593698 to your computer and use it in GitHub Desktop.
Save dongweiming/7593698 to your computer and use it in GitHub Desktop.
#!/usr/bin/expect
#使用expect登陆服务器脚本
#dongweiming 2013.04.02
set timeout 5
set server [lindex $argv 0]
set port [lindex $argv 1]
set password [lindex $argv 2]
set tbjpass XXX
if {$port==""} {
set port 20000
}
if {$argc>3} {
puts stderr "参数错误,请使用以下格式: $argv0 [服务器简称,比如8 ] [端口]"
exit 1
}
if {$server=="100"} {
spawn ssh -p 20000 tbj
expect "password:"
send "$tbjpass\n"
interact
} elseif {[regexp {^s} $server found]} {
spawn ssh -p 20000 tbj
expect "password:"
send "$tbjpass\n"
expect "~"
send "ssh $server\n"
expect "password:"
send "admaster$server\n"
interact
} else {
spawn ssh -p $port dongwm@$server
interact
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment