我的任务是关闭约30-40个思科交换机上的http。使用plink.exe
我已经能够正确配置它们,但这有点单调乏味。
我开始尝试编写批处理脚本,其目标是询问主机和切换密码,然后输入这两个变量并继续输入其余文本。似乎程序启动时,批处理脚本暂停并等待它终止,然后继续执行其余的脚本。
有没有办法将文本传输到plink进程?
供参考,到目前为止,这是我的代码:(我已经使用//添加了评论,虽然这些不在实际代码中)
@ECHO on
set /p host="Enter host: "
set /p password="Enter Password: "
"C:\Program Files (x86)\PuTTY\plink.exe" -ssh cisco@%host% //starts plink
timeout 3 //waits for connection to be established
cisco //inputs cisco as the username
timeout 1
%password% //waits for the password prompt and enters it
configure
timeout 1
no ip http server //disables http
timeout 1
end //returns to the starting menu
timeout 1
copy running-config startup-config /copies from running to startup config
timeout 1
y //confirms the operation from running to startup
pause //just here so I can review errors
exit
使用@ eryksun&#39>方法更新新代码
@ECHO off
set /p host="Enter host: "
set /p password="Enter Password: "
(echo configure & (timeout 1 >nul)
echo no ip http server
(timeout 1 >nul)
echo end
(timeout 1 >nul)
echo copy running-config startup-config
(timeout 1 >nul) & (pause >nul) & exit
) | "C:\Program Files (x86)\PuTTY\plink.exe" -v -l cisco -pw %password% -ssh %host%
pause
和输出:
Using username "cisco".
Sent password
Access granted
Opening session as main channel
Opened main channel
Allocated pty (ospeed 38400bps, ispeed 38400bps)
Started a shell/command
switch#configure
no ip http server
end
←[Kswitch(config)#switch(config)#copy running-config startup-config
←[Kswitch#Overwrite file [startup-config].... (Y/N)[←[1mN←[0m] ?N
switch#