使用批处理在腻子中输入第二个用户名和密码
input second username and password in putty using batch
我想知道如何在初始登录成功后自动在putty中输入用户名和密码。
我有一个bat文件connect.bat
@echo off
putty [user]@[host] -pw [password]
在我 运行 之后,它会打开一个新的 putty window 并验证登录。
成功后,我没有被重定向到 shell 而是另一个登录屏幕。以下示例。
然后我需要通过键入以下内容手动输入不同的用户名和密码。
[username]
[ENTER KEY]
[password]
[ENTER KEY]
最终将重定向到主持人的菜单。
我尝试了以下方法:
echo [username] & [password] | putty [user]@[host] -pw [password]
putty [user]@[host] -pw [password] < user_pass.txt
putty [user]@[host] -pw [password] -m user_pass.txt
但失败了,有没有办法通过 batch/powershell 脚本执行此操作,或者我应该合并另一个应用程序?
您可以尝试 Sendkeys method:
@if (@CodeSection == @Batch) @then
@echo off
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
rem Start the other program in the same Window
start "" /B putty [user]@[host] -pw [password]
rem Send the additional keys
%SendKeys% "[username]{ENTER}"
ping -n 2 localhost > NUL
%SendKeys% "[password]{ENTER}"
goto :EOF
@end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
我想知道如何在初始登录成功后自动在putty中输入用户名和密码。
我有一个bat文件connect.bat
@echo off
putty [user]@[host] -pw [password]
在我 运行 之后,它会打开一个新的 putty window 并验证登录。
成功后,我没有被重定向到 shell 而是另一个登录屏幕。以下示例。
然后我需要通过键入以下内容手动输入不同的用户名和密码。
[username]
[ENTER KEY]
[password]
[ENTER KEY]
最终将重定向到主持人的菜单。
我尝试了以下方法:
echo [username] & [password] | putty [user]@[host] -pw [password]
putty [user]@[host] -pw [password] < user_pass.txt
putty [user]@[host] -pw [password] -m user_pass.txt
但失败了,有没有办法通过 batch/powershell 脚本执行此操作,或者我应该合并另一个应用程序?
您可以尝试 Sendkeys method:
@if (@CodeSection == @Batch) @then
@echo off
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
rem Start the other program in the same Window
start "" /B putty [user]@[host] -pw [password]
rem Send the additional keys
%SendKeys% "[username]{ENTER}"
ping -n 2 localhost > NUL
%SendKeys% "[password]{ENTER}"
goto :EOF
@end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));