1

ncatを使用してISPとそのポートへの接続を開く簡単なbashスクリプトを作成したいと思います。

最初のコマンドは次のようになります。

nc address port

これを行うと、最初にユーザー名を入力するように求められます。Enterキーを押す必要があります。次に、パスワードの入力を求められ、もう一度Enterキーを押す必要があります。

この後、ターミナルプロセスウィンドウを開きます。このタイプのスクリプトに十分なリソースを誰かに教えてもらえますか?

ユーザー名とパスワードはすでに知っていますが、それを入力してEnterキーを押す必要があるという事実を回避する方法がよくわかりません。また、新しいターミナルプロセスを開く方法もわかりません。

前もって感謝します!

4

2 に答える 2

3

期待スクリプトをチェックしてください 期待

例:

# Assume $remote_server, $my_user_id, $my_password, and $my_command were read in earlier
# in the script.
# Open a telnet session to a remote server, and wait for a username prompt.
spawn telnet $remote_server
expect "username:"
# Send the username, and then wait for a password prompt.
send "$my_user_id\r"
expect "password:"
# Send the password, and then wait for a shell prompt.
send "$my_password\r"
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, or written to disk.
set results $expect_out(buffer)
# Exit the telnet session, and wait for a special end-of-file character.
send "exit\r"
expect eof
于 2013-03-12T22:23:20.193 に答える
1

秘密はヒアドキュメントにあります

この問題は、次のようなもので解決できます。

$ command-that-needs-input <<EOF
authenticate here
issue a command
issue another command
EOF

ヒアドキュメント用に提供したリンクを見てください。これには、変数置換やその他の多くの便利な機能のサポートが含まれています。楽しみ!

于 2013-03-12T22:20:38.100 に答える