expectスクリプトでexpectコマンドをどのようにして正確な文字列が一致するのを待ってからスクリプトの次の行に進むかを知りたい。expectプログラムスクリプトのexpectコマンドを正確な文字列の一致を待つ方法
Bourneシェル(SH)スクリプト:
#!/bin/sh
#!/usr/bin/expect
spawn ssh -Y [email protected]
expect -exact "[email protected]'s password: "
# replace password with ur own passwd
send "geomax45\r"
# replace the prompt with ur own prompt
expect "[email protected]:~$ "
# run application
send "./sample\r"
expect "*Menu*\r
1. print hello world\r
2. print Bye world\r
3. quit\r
enter choice: "
# enter choice 1
send "1\r"
expect "Bye world\r
*Menu*\r
1. print hello world\r
2. print Bye world\r
3. quit\r
enter choice: $"
# enter choice 2
send "2\r"
上記のコードでコード1を入力した後は、画面上で発生する "さようなら世界\ rを......" という文字列を待つ必要があります。しかし、画面に別の文字列が表示されても、コードは次の行を実行して、オプション2を入力します。これは、expectの定義に従って行われません。 expectコマンドの完全な文字列が一致するまで待機する必要があります。
厳密な文字列の一致が発生するまで待つように、より厳しいコマンドを使用できるかどうかを知りたいです。この問題で私を助けてください
あなたのスクリプトに 'exp_internal 1'を追加してください - これは冗長で、あなたが今試合が試行されていることを示しているので、なぜ試合が成功したのか分かります。 –