2017-03-11 48 views

回答

0

這可以幫助你

#!/usr/bin/expect 
set timeout -1 

spawn -noecho bash -c "ssh -t [email protected] '<here-comes-your-command>'" 

expect { 
    -re ".*assword.*" { 
    exp_send "$env(PASS_WORD)\n" 
    exp_continue 
    } 
} 

注: -

1)腳本複製到遠程主機在運行之前。傳遞整個腳本並不是件好事。 2)使用期望訪問環境變量時,使用$env(variable_name)

在上例中,對於$PASS_WORD,我使用了$env(PASS_WORD)