
リモート Unix マシンで (ローカル) Windows コマンド シェルから (Tcl などの) スクリプトを実行する必要があり、スクリプトの stdout/stderr を Windows CLI に表示する必要があります。終了コードも役立ちます。
これは ssh (putty) を使用して可能ですか? または他の方法でも可能ですか?
答え1
これは SSH のデフォルトです。出力をリモートでリダイレクトする場合は、コマンド引用符内にリダイレクト記号 (通常は「>」) を入れます。
例えば:
ssh remote_host "ls > /tmp/file_on_remote_host.txt"
Windowsホストに出力をローカルに保存するには、
ssh remote_host "ls" > .\file_on_local_host.txt
stderrをリモートで結合し、それをstdoutとローカルに保存するには、
ssh remote_host "ls 2>&1" > .\combined_output_on_local_host.txt
答え2
私が探していたのはパテの相棒です実行ファイルターミナル エミュレータのように動作する putty とは異なり、plink
通常の (非対話型の) CLI プログラムのように動作します。
これを使用すると、これを実行しcmd.exe
、リモート コマンドの出力をローカルに保存できます。
\> plink remote_host "ls -l" > log.txt
何よりも、これはssh同様にテルネット!
参考までに、利用可能なオプションは次のとおりです。
PuTTY Link: command-line connection utility
Release 0.59
Usage: plink [options] [user@]host [command]
("host" can also be a PuTTY saved session name)
Options:
-V print version information and exit
-pgpfp print PGP key fingerprints and exit
-v show verbose messages
-load sessname Load settings from saved session
-ssh -telnet -rlogin -raw
force use of a particular protocol
-P port connect to specified port
-l user connect with specified username
-batch disable all interactive prompts
The following options only apply to SSH connections:
-pw passw login with specified password
-D [listen-IP:]listen-port
Dynamic SOCKS-based port forwarding
-L [listen-IP:]listen-port:host:port
Forward local port to remote address
-R [listen-IP:]listen-port:host:port
Forward remote port to local address
-X -x enable / disable X11 forwarding
-A -a enable / disable agent forwarding
-t -T enable / disable pty allocation
-1 -2 force use of particular protocol version
-4 -6 force use of IPv4 or IPv6
-C enable compression
-i key private key file for authentication
-noagent disable use of Pageant
-agent enable use of Pageant
-m file read remote command(s) from file
-s remote command is an SSH subsystem (SSH-2 only)
-N don't start a shell/command (SSH-2 only)
-nc host:port
open tunnel in place of session (SSH-2 only)
答え3
はい、putty ssh クライアントを使用すると、スクリプトが生成するすべてのコマンド ライン出力が表示されます。スクリプトの実行後に終了コードを取得するには、次のように入力します。
echo $?
答え4
もう一つの答え:
すべてのLinuxコマンドを保存するコマンドリスト.txtファイルを開き、以下のコマンドを使用します。
plink.exe -ssh -pw パスワード[メールアドレス] 出力.txt
パスワード==デバイスログインのパスワード
名前==デバイスログインのユーザー名
1.2.3.4==デバイスのIPアドレス
このコマンドを実行すると、すべてのcmdlist.txtコマンドがリモートデバイス上で実行され、出力はoutput.txtというファイルに保存されます。
plink.exe と cmdlist.txt を同じディレクトリに保存し、DOS プロンプトを同じディレクトリに向けるようにしてください。