TCL Expect

#!/usr/bin/expect -f

proc terminal:password:get {promptString} {

     # Turn off echoing, but leave newlines on.  That looks better.
     # Note that the terminal is left in cooked mode, so people can still use backspace
     exec stty -echo echonl <@stdin

     # Print the prompt
     puts -nonewline stdout $promptString
     flush stdout

     # Read that password!  :^)
     gets stdin password

     # Reset the terminal
     exec stty echo -echonl <@stdin

     return $password
}

proc chooseMachine { } {
    puts "1) 11.192.101.216 (pre/ccvob);\n2) 11.192.101.192;\n3) 11.192.101.236;\n4) 11.192.101.221;";
    gets stdin choice;
    switch $choice {
        1 {
            return "11.192.101.216";
        }
        2 {
            return "11.192.101.192";
        }
        3 {
            return "11.192.101.236";
        }
        4 {
            return "11.192.101.221";
        }
        default {
            return "11.192.101.216";
        }
    }
}

proc main { } {
    set timeout -1;
    set IP [ chooseMachine ];
    set PASSWORD [ terminal:password:get "请输入密码:" ];
    puts "Start build source success";
    spawn ssh van.yzt@11.239.182.250;
    expect "*password:";
    send "$PASSWORD\r";
    expect "*$*";
    set TOKEN [ terminal:password:get "请输入6位令牌:" ];
    spawn ssh van.yzt@login1.am100.alibaba-inc.com;
    expect "*password*";
    send "$PASSWORD$TOKEN\r";
    expect "*$*";
    send "ssh van.yzt@$IP\r";
    expect "password:";
    send "$PASSWORD\r";
    expect "*$*";
    send "sudo su admin\r";
    expect "*password*";
    send "$PASSWORD\r";
    expect "*$*";
    interact;
    exit 0;
}

[ main ];