2017-11-03 2 views
0

私はsshを5ボックスに入れ、aptitude dist-upgrade -dを実行し、パッケージを圧縮して元のボックスに戻します。長いスクリプトを使わずに、繰り返しのためのexpectを使用するにはどうすればよいですか?

すべてのボックスは同じパスワードを持ち、dist-upgradeにyesと言うにはすべてのボックスに「y」という入力が必要です。

私の現在の期待スクリプトは私の質問は、それがパスワードを送信するためのパスワードを聞かれる場合ようにI「重複排除」これを行う方法、である次

## Original box 
expect "password" 
send "Password\n" 
## Box sshing to 
expect "password" 
send "Password\n" 
expect "want to continue?" 
send "y\n" 

の繰り返しの負荷で長いと厄介ですcontinueプロンプトが表示されたら、yを送信します。私は(時々キーチェックが、私は「はい」を送信する必要がミックスにスローされた)とき来るかの完璧な順序を取得する必要がないように

全スクリプト以下:

#!/usr/bin/expect -f 
set timeout -1 
## This uses manualpatching.sh, used to zip up a list of the latest Debian packages 
spawn ./manualpatching.sh 
## BOX1 
expect "password" 
send "Password\n" 
expect "want to continue?" 
send "y\n" 
## BOX2 
expect "password" 
send "Password\n" 
expect "password" 
send "Password\n" 
expect "want to continue?" 
send "y\n" 
expect "password" 
send "Password\n" 
expect "connecting" 
send "yes\n" 
## BOX3 
expect "password" 
send "Password\n" 
expect "password" 
send "Password\n" 
expect "want to continue?" 
send "y\n" 
expect "password" 
send "Password\n" 
## BOX4 
expect "password" 
send "Password\n" 
expect "password" 
send "Password\n" 
expect "want to continue?" 
send "y\n" 
expect "password" 
send "Password\n" 
## BOX5 
expect "password" 
send "Password\n" 
expect "password" 
send "Password\n" 
expect "want to continue?" 
send "y\n" 
expect "password" 
send "Password\n" 
## BOX6 
expect "password" 
send "Password\n" 
expect "password" 
send "Password\n" 
expect "want to continue?" 
send "y\n" 
expect "password" 
send "Password\n" 
## END 
expect eof 
+0

あなたのスクリプトを表示してください! – Gaurav

+0

さて、今投稿を編集します –

+0

ありがとうございました。ありがとうございました –

答えて

3

Gauravに感謝して私に正しい方向を教えてください。私は右のexp_continueを使用してダウン私のスクリプトをスリム化

、それは今はるかにきれいで、汎用性があります:

#!/usr/bin/expect -f 
set timeout -1 
spawn ./manualpatching.sh 
expect { 
     "Are you sure you want to continue connecting (yes/no)" { 
      send "yes\r" 
      exp_continue 
     } 
     "password" { 
      send "Password\r" 
      exp_continue 
     } 
     "want to continue?" { 
      send "y\r" 
      exp_continue 
     } 
} 
+0

"続ける"アクションブロックの後に 'eof'を追加するだけです。 –

+0

私の知らないことは申し訳ありませんが、どうしますか? –

+1

今、expectループから抜け出すパターンはありません。すべてのブランチは 'exp_continue'を使います。 'eof'を期待すると、あなたが作成したプログラムが終了すると期待しているあなた(そしてこのスクリプトを管理する他の誰か)のための明示的なリマインダであり、スクリプトは続けられます。 –

関連する問題