
(로컬) Windows 명령 셸에서 원격 Unix 시스템의 (Tcl 등) 스크립트를 실행해야 하며 스크립트의 stdout/stderr이 Windows CLI에 표시되기를 원합니다. 종료 코드도 유용합니다.
SSH(퍼티)를 사용하여 이것이 가능합니까? 아니면 다른 수단으로?
답변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
제가 찾던건 퍼티의 사이드킥인데,plink.exe. 터미널 에뮬레이터처럼 작동하는 퍼티와 달리 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 명령을 다음 위치에 저장하세요.cmdlist.txt파일을 다운로드하고 아래 명령을 사용하십시오.
plink.exe -ssh -pw 비밀번호[이메일 보호됨] 출력.txt
비밀번호==장치 로그인을 위한 비밀번호
이름을 밝히다==장치 로그인을 위한 사용자 이름
1.2.3.4==장치 IP 주소
이 명령이 실행되면 모든 cmdlist.txt 명령이 원격 장치에서 실행되고 출력은 output.txt라는 파일에 저장됩니다.
plink.exe와 cmdlist.txt를 동일한 디렉토리에 유지하고 dos 프롬프트가 동일한 디렉토리를 가리키도록 하세요.