sshを使ってリモートコンプに接続する必要のあるbash + expectスクリプトを持っています(ここではパスワードの識別が必要です)そのファイルを "hostname"( "hostname aaaa1111"のような)で特定の行を見つけ、このホスト名をwhileの後に使用する変数に格納します。 "hostname"パラメータの値を取得するにはどうすればよいですか?私はラインの内容が$ expect_out(バッファ)変数にあると思ったので(それをスキャンして分析することができます)、そうではありません。私のスクリプトは次のとおりです。リモートコンピュータ上でcatを実行し、期待値を使って変数を出力する
#!/bin/bash
----bash part----
/usr/bin/expect << ENDOFEXPECT
spawn bash -c "ssh [email protected]$IP"
expect "password:"
send "xxxx\r"
expect ":~#"
send "cat /etc/rc.d/rc.local |grep hostname \r"
expect ":~#"
set line $expect_out(buffer)
puts "line = $line, expect_out(buffer) = $expect_out(buffer)"
...more script...
ENDOFEXPECT
私はライン変数を参照してくださいしようとすると、私はこれだけを参照してください。line = , expect_out(buffer) = (buffer)
変数にファイルから行を取得するための正しい方法は何ですか? または、リモートコンピュータにファイルを開き、ファイルをスキャンして変数に必要なものを取得することは可能ですか? はここhttp://en.wikipedia.org/wiki/Expect例があります:
# Send the prebuilt command, and then wait for another shell prompt.
send "$my_command\r"
expect "%"
# Capture the results of the command into a variable. This can be displayed,
set results $expect_out(buffer)
が、それはこの場合には動作しないようですか?
タイトルをあなたの質問をより詳しく説明するようにしてください。 – Brandon
質問[サーバーフォールトに表示されます](http://serverfault.com/q/300238/30957) –
...まだ回答なし、残念ながら – lugger1