2016-07-28 46 views
0

我正在瘋狂地嘗試使這個作品。Bash在相同的過程中期待兩個命令

我需要使用期望來設置幾個密碼。我的問題是我必須在同一個處理器中運行兩個命令。

下面的代碼

yum install -y expect 
    secret="price_aws_git_secret.txt" 
    eval $(ssh-agent) 
    pass=$(cat $secret) 
    expect << EOF 
      spawn ssh-agent ssh-add price_aws_github 
      expect "Enter passphrase" 
      send "$pass\r" 
      spawn git clone [email protected]/repo.git 
      expect "Are you sure you want to continue connecting" 
      send "yes\r" 
      expect eof     
    EOF 

第一個命令添加到SSH代理SSH密鑰,第二個命令git的克隆需要在同一過程中獲得該代理。

尋找文檔和示例我無法看到期望如何在同一過程中使用兩個命令。

有什麼建議嗎?

謝謝!

+0

像往常一樣,您應該能夠通過設置公鑰驗證來完全避免「期望」。 – chepner

+0

這就是我所做的,但即使在github上添加了公鑰和私鑰,當您想要將私鑰添加到ssh-add時,您還需要提供密碼 – paul

+0

您將竭盡全力。你爲什麼不創建一個沒有密碼的密鑰? –

回答

2

關於使用ssh密鑰更好的建議,以回答你的問題。您不需要同時與兩個進程交互。您需要處理第一個,然後從第二個開始:

expect << EOF 
     spawn ssh-agent ssh-add price_aws_github 
     expect "Enter passphrase" 
     send "$pass\r" 
     # assume this works. if not, there's more work to do 
     expect eof 
     close 

     spawn git clone [email protected]/repo.git 
     expect "Are you sure you want to continue connecting" 
     send "yes\r" 
     expect eof     
EOF