2017-06-15 19 views
-1

私はアンバリサーバーのインストールを自動化するためのスクリプトを書いています。 私はambari-serverの設定を自動化するためにtclスクリプトを作成しました。私の問題は1つの場所でダウンロードしてjdkをインストールし、そのステップに少し時間がかかり、一方で他の期待通りの送信が画面上に現れ始め、すべてのインストールが失敗する。TCLの2つの間の遅延

マイスクリプト:

#!/usr/bin/expect 

spawn sudo ambari-server setup 

expect "OK to continue" 
send "y\r" 

expect "Customize user account for ambari-server daemon" 
send "y\r" 

expect "Enter user account for ambari-server daemon (root):" 
send "root\r" 

expect "Enter choice (1):" 
send "1\r" 

expect "Do you accept the Oracle Binary Code License Agreement" 
send "y\r" 

expect"Enter advanced database configuration" 
send "y\r" 

expect "Enter choice (1):" 
send "3\r" 

expect "Hostname (localhost):" 
send "localhost\r" 

expect "Port (3306):" 
send "3306\r" 

expect "Database name (ambari):" 
send "ambari\r" 


expect "Username (ambari):" 
send "ambari\r" 


expect "Enter Database Password (bigdata):" 
send "password\r" 

expect "Proceed with configuring remote database connection properties" 
send "y\r" 

それはダウンロードしてインストールしたJDKを、その期間中に、それは次のexceptsでの送信を服用開始しますOracleのバイナリコードライセンス契約書を受け入れた後。

誰かが、前のものがまだ動作している間に、exceptの実行を止める方法を教えてもらえますか? 私は何かを試すためにアフターとスリープをしようとしましたが、うまくいきませんでした。 ありがとう

+0

はなぜ誰かがこれをdownvoteでしょうか?どのように十分な質問をするのが適切ではないのですか?私は自分のコードを共有した、私は何を試してみました。あなたがdownvotingで多くの努力をしているのであれば、あなたがそれをした理由を親切に残してください。 –

+0

jdkをインストールするのに十分な時間だけset timeoutを入れて、一時的な修正を見つけました。まだ誰かがより良い解決策を提案できるなら、それは本当に素晴らしいでしょう。 –

+0

jdkのダウンロードとインストールの終了時にインストールsctiptの出力を表示できますか? – komar

答えて

0

timeoutを変更するのが正しい方法です。私は書くだろう:

expect "Do you accept the Oracle Binary Code License Agreement" 
set old_timeout $timeout ;# remember the previous value 
set timeout -1    ;# disable the timeout 
send "y\r" 

expect"Enter advanced database configuration" 
set timeout $old_timeout ;# restore the timeout 
send "y\r" 
0

あなたのコードには、期待される文字列が受信されなかった場合の対処方法がありません。それらを追加するのは良いスタイルでしょう。さもなければ、文字列が割り当てられた時間(デフォルトでは10秒)内に受け取られなかった場合、スクリプトはあなたが見た通りに続行します。

1つのexpectコマンドに異なるタイムアウトを使用するには、単に-timeoutオプションを使用します。たとえば、JDKの10分は、インストールを許可します

expect -timeout 600 "Enter advanced database configuration" 
send "y\r" 

、失敗した場合の追加のハンドラを持つ:

expect { 
    -timeout 600 
    "Enter advanced database configuration" { 
     send "y\r" 
    } 
    default { 
     error "jdk failed to install in time" 
    } 
} 
関連する問題