当前位置: 动力学知识库 > 问答 > 编程问答 >

windows, Putty, pscp combined in to a single batch file, is it possible?

问题描述:

I'm having trouble getting an answer to my question, in laymens terms. It is probably my lack of knowledge on the subject so, I'm dumbing down the question. I have a windows machine that I run the putty tool from and connect to a linux box. I run " killall /bob/bin/myfile.out " then close putty then type in a cmd prompt pscp.exe myfilet.out.2.3.4 [email protected]:/bob/bin/myfile.out . Can someone show me how to combine these into a single windows batch file? thank you

网友答案:

You could use the free command line tool Plink to run commands on external servers via SSH.

@echo off
Plink [email protected] "killall /bob/bin/myfile.out"
pscp.exe myfilet.out.2.3.4 [email protected]:/bob/bin/myfile.out || echo an error occurred when copying the file.

the command after || on the second line will only run if an error level is set by the previous command.

网友答案:

I can't add comments yet, but can you elaborate on how you login with putty, but not do the exact same thing with plink? Plink not only accepts all the same options as putty, but if you have a saved session in putty, you can access it from plink. Without any subcommands, plink should essentially make you CMD shell look like a crude putty window, with subcommands, it will execute them and return:

C:\Users\riglerjo>plink savedputtysession
Using username "rigler".
# hostname
 s9-chicago.accountservergroup.com
-bash-3.2$ exit
logout

Run the remote command as an option on plink:

C:\Users\riglerjo>plink savedputtysession hostname
s9-chicago.accountservergroup.com
分享给朋友:
您可能感兴趣的文章:
随机阅读: