Created
June 2, 2016 07:26
-
-
Save jorben/80b1859af120e268dda0881998d9c2b5 to your computer and use it in GitHub Desktop.
远程批量执行脚本
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect -f | |
set type [lindex $argv 0 ] | |
set ip [lindex $argv 1 ] | |
set cmd [lindex $argv 2 ] | |
set timeout 10 | |
if { $ip == "" } { | |
puts "Usage: go web 1.2.3.4" | |
puts "Usage: go app 1.2.3.4 dev" | |
puts "Usage: go tws 10.137.15.150,10.198.133.45 'uptime'" | |
exit | |
} | |
if { $type == "web" } { | |
set username usernameforweb | |
set password passwordforweb | |
} | |
if { $type == "app" } { | |
set username usernameforapp | |
set password passwordforapp | |
} | |
if {[file exists $ip]} { | |
set fd [open $ip r] | |
while { [gets $fd line] >= 0 } { | |
spawn ssh $username@$line $cmd | |
expect { | |
"*yes/no" { send "yes\r"; exp_continue} | |
"*assword:" { send "$password\r" } | |
} | |
interact | |
} | |
} else { | |
foreach line [split $ip ","] { | |
spawn ssh $username@$line $cmd | |
expect { | |
"*yes/no" { send "yes\r"; exp_continue} | |
"*assword:" { send "$password\r" } | |
} | |
interact | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment