Skip to content

Instantly share code, notes, and snippets.

@fasheng
Created October 18, 2013 11:47
Show Gist options
  • Save fasheng/7040434 to your computer and use it in GitHub Desktop.
Save fasheng/7040434 to your computer and use it in GitHub Desktop.
Speed up setup for goagent through expect script.
#! /usr/bin/expect -f
set timeout 60
if {$argc != 2} {
set scriptname [lindex [split $argv0 "/"] end]
send_user "Usage: $scriptname \"APPID01|APPID02..\" <email>\n"
exit
}
proc getpass pwprompt {
set oldmode [stty -echo -raw]
send_user "\n$pwprompt"
set timeout -1
expect_user -re "(.*)\n"
send_user "\n"
eval stty $oldmode
return $expect_out(1,string)
}
set appids [lindex $argv 0]
set appidlist [split [lindex $argv 0] "|"]
set email [lindex $argv 1]
set password [getpass "Please enter password: "]
set python "python2"
set uploader "/usr/share/goagent/server/uploader.zip"
set command "$python $uploader"
spawn $python $uploader
expect -nocase "appid:" {send "$appids\r"}
for {set i 0} {$i < [llength $appidlist]} {incr i} {
set appid [lindex $appidlist $i]
expect -nocase "application:" {send_user "\n\n==> Setup up appid: $appid"}
expect -nocase "email:" {send "$email\r"}
expect -nocase "password for" {send "$password\r"}
expect -nocase "email:" {send "$email\r"}
expect -nocase "password for" {send "$password\r"}
}
expect "上传成功" {send "\r"}
interact
@fasheng
Copy link
Author

fasheng commented Oct 18, 2013

Usage:

sudo ./expect_goagent.tcl "appid01|appid02" your@gmail.com

Then input your password runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment