是否可以使用批处理文件来建立一个telnet会话,发送一个命令并写入文件的输出? [英] Is it possible to use a batch file to establish a telnet session, send a command and have the output written to a file?
问题描述
我运行批处理文件来建立Telnet会话的设备,并创建将举行从设备拉到信息的文件。
I run the following batch file to establish a telnet session to a device and create a file that will hold information pulled from the device.
CD\
COLOR 0E
CLS
@echo off
ECHO This will start the connection to the Heraeus QuicK-Lab DATACAST ENtouch.
pause
telnet 172.17.0.16 4224 -f C:\LogFiles\Datacast.log
在telnet会话建立我命令类型为code的最后一行指定数据转储到Datacast.log后。我希望能在包括批处理文件命令(M3,1,999为例),但不知何故,我可以找到没有类似的例子。
After the telnet session is established I type in a command to dump data to Datacast.log as specified in the last line of code. I am hoping to include the command ("M3,1,999" for example) in the batch file somehow but I can find no similar examples.
是否有可能有一个批处理文件来做到这一点?
Is it possible to do this with a batch file?
推荐答案
也许这样的事情?
创建一个批处理连接到telnet和运行一个脚本来发出命令? <一href=\"http://social.technet.microsoft.com/Forums/sv/winserverpowershell/thread/1a230ff9-2ec1-41db-b72b-47c40e595eb0\"相对=nofollow>来源
Create a batch to connect to telnet and run a script to issue commands ? source
:: Open a Telnet window
start telnet.exe 192.168.1.1
:: Run the script
cscript SendKeys.vbs
命令文件(名为SendKeys.vbs):
set OBJECT=WScript.CreateObject("WScript.Shell")
WScript.sleep 50
OBJECT.SendKeys "mylogin{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "mypassword{ENTER}"
WScript.sleep 50
OBJECT.SendKeys " cd /var/tmp{ENTER}"
WScript.sleep 50
OBJECT.SendKeys " rm log_web_activity{ENTER}"
WScript.sleep 50
OBJECT.SendKeys " ln -s /dev/null log_web_activity{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "exit{ENTER}"
WScript.sleep 50
OBJECT.SendKeys " "
这篇关于是否可以使用批处理文件来建立一个telnet会话,发送一个命令并写入文件的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!