[英]“command not found” errors in expect script executed by shell script
我正在嘗試實現“shell腳本調用expect腳本”,這樣它就不會提示用戶每次輸入ssh密碼。 我開始使用變量的值作為scp,ssh等的密碼,而不是每次都提示用戶輸入,並且理解我應該有.sh
文件和.exp
文件。 我expect
在我的系統中安裝(運行expect -v
顯示expect version 5.43.0
)。
在我的upload-to-server.sh
文件中
cd $SOURCE_PATH/shell
./password.exp $DESTINATION_PATH $SSH_CREDENTIALS $PROJECT_INSTALLATION_PATH $PASSWORD
在我的password.exp
文件中,我有
#!/usr/bin/expect -f
set DESTINATION_PATH [lindex $argv 0];
set SSH_CREDENTIALS [lindex $argv 1];
set PROJECT_INSTALLATION_PATH [lindex $argv 2];
set PASSWORD [lindex $argv 3];
spawn scp $DESTINATION_PATH/exam.tar $SSH_CREDENTIALS':/'$PROJECT_INSTALLATION_PATH
expect "password:"
send $PASSWORD"\n";
interact
在運行upload-to-server.sh
文件時,我收到以下錯誤 -
./password.exp: line 9: spawn: command not found
couldn't read file "password:": no such file or directory
./password.exp: line 11: send: command not found
./password.exp: line 12: interact: command not found
我從多個來源(不了解太多基礎知識)到達上面的代碼(在exp文件中)。 在一個來源中 ,代碼就是這樣
#!/usr/local/bin/expect
spawn sftp -b cmdFile user@yourserver.com
expect "password:"
send "shhh!\n";
interact
#!/usr/local/bin/expect -f
set TESTCASE_HOME [lindex $argv 0];
set TESTCASE_LIST [lindex $argv 1];
set PASSWORD [lindex $argv 3];
set timeout 200
spawn $TESTCASE_HOME/dobrt -p $TESTCASE_HOME/$TESTCASE_LIST
expect "*?assword:*" {send -- "$PASSWORD\r";}
expect eof
那里有一些差異 -
#!/usr/local/bin/expect
行中有一個額外的-f
期待“ ?assword: ”{send - “$ PASSWORD \\ r”;}與expect "password:" send "shhh!\\n";
不同, expect "password:" send "shhh!\\n";
interact
取代了expect eof
。
這是我的第一個expect script
所以不知道要編碼什么。 有什么指針嗎?
謝謝,
Sandeepan
不要做任何這個! 您應該使用公鑰認證作為上面的評論建議。 你的方式將密碼保持清晰,易碎。
公鑰認證更容易設置,例如: 設置說明
你確定你在做什么嗎?
./script.exp
並不是
. ./script.exp
?? 后者會讓shell試圖解釋期望程序。
完全同意ssh密鑰是正確的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.