简体   繁体   English

执行Windows批处理文件

[英]Executing the windows batch file

What I am doing currently- 我目前在做什么-

  1. Execute the shell script on MachineB from MachineA (Windows Environment). MachineA (Windows Environment)在MachineB上执行shell脚本。
  2. Then wait for the shell script to complete its task, in my case it will write the output to a text file. 然后等待shell脚本完成其任务,在我的情况下,它将把输出写入文本文件。
  3. And after the shell script has completed all its task means it finished writing everything to a txt file, then copy that txt file to MachineA (Windows Environment) from MachineB . 而shell脚本已经完成了所有的任务后,意味着它写完一切到一个txt文件,然后复制TXT文件MachineA从(Windows环境下) MachineB

So for this I wrote a Windows Batch file that will do the above task and it is working fine for me. 因此,为此,我编写了一个Windows Batch file ,它将完成上述任务,并且对我来说工作正常。 Below is the Windows Bat file that I am using currently. 以下是我当前使用的Windows Bat文件。

plink uname@machineB -m email.sh 
pscp  uname@machineB:/export/home/uname/jk_attachment22.txt C:\PLINK\foo.txt

But by using the above windows batch file, I need to type password two times which is pain, Firstly I need to type for the first line and then again for the second line. 但是通过使用上面的Windows批处理文件,我需要两次键入密码,这很痛苦,首先,我需要在第一行中键入,然后在第二行中再次键入。

My Question is- 我的问题是-

So Is there any way I can run the above windows batch file by just typing password once at the command prompt. 所以有什么办法可以通过在命令提示符下键入一次password来运行上述Windows批处理文件。 Any suggestions will be appreciated. 任何建议将不胜感激。

This is what I have when I was looking for /.ssh folder . 这是我在寻找/.ssh folder

Update: 更新:

bash-3.00$ cd ~/.ssh
bash-3.00$ pwd
/home/uname/.ssh
bash-3.00$ ls -lt
total 2
-rw-r--r--   1 uname   gid-uname     489 Jul 26 18:55 known_hosts

So I need to make some other changes here? 所以我需要在这里进行其他更改吗?

I'd skip the password and auth with ssh key. 我会跳过密码并使用ssh键进行身份验证。 http://www.debian-administration.org/articles/152 http://www.debian-administration.org/articles/152

Use the -pw option in your command line utilities. 在命令行实用程序中使用-pw选项。

Let's say you name your batch file TWINKIE.BAT. 假设您将批处理文件命名为TWINKIE.BAT。 At the command prompt, you'd type "TWINKIE password", where "password" is the actual password you want to use. 在命令提示符下,键入“ TWINKIE password”,其中“ password”是您要使用的实际密码。

C:\>twinkie password

The "password" is passed into your batch file as the first command line variable, %1. “密码”作为第一个命令行变量%1传递到批处理文件中。 Your batch file would be: 您的批处理文件将是:

plink -pw %1 uname@machineB -m email.sh
pscp  -pw %1 uname@machineB:/export/home/uname/jk_attachment22.txt C:\PLINK\foo.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM