Automate telnet commands from DOS

PJan8724
PJan8724 used Ask the Experts™
on
Hello all,

I have a current need for a way to automate login and commands to fiber switches (Brocade, McData) from a DOS batch file, and save the output to a text file.  I cannot install an application, as this will be run on different windows machines everytime (new sites).  So I need a stand alone utility.

I found this thread that lead me to a great utility:

http://www.experts-exchange.com/Hardware/Routers/Q_21108412.html

Telnet Scripting Tool (TST10) by Albert Yale is exactly what I needed.  

Unfortunately the homepage and email address no longer exist, but here is a good place to download it:

http://users.skynet.be/bk330420/gg/albert.html

It works excellent on the DS32B Brocade switches, but I'm having a problem when running it against the DS16B switches.

The basic idea with TST10 is you create a text file with WAIT/SEND commands (I use the batch file to dynamically write this file), and run TST10.exe against it.  It will look for the pattern you define with WAIT, and respond with your SEND commands.  The problem I am having is for some reason this particular model hangs after the first SEND command.

I am sending this against a Brocade switch:

1.2.3.4 23
WAIT "login:"
SEND "administrator\m"
WAIT "Password:"
SEND "mypassword\m"
WAIT ">"
SEND "my commands"

TST10.exe uses "\m" to send a carriage return.  These exact commands work wonderfully on a DS32B.  When running it against a DS16B, it hangs after sending my username.  On the console that pops up (you can interact with it while the script runs,) I can see that a carriage return is indeed entered after it sends "administrator", but the switch does not seem to accept it.  The cursor moves down a line, but the "password:" prompt does not appear (my second WAIT definition).  In fact, if I specify multiple "\m", the cursor will move down that many lines, but I will not see the "password:" prompt.  After some troubleshooting, it seems this particular Brocade model is looking for "control+enter".  If I enter this key combination manually, I will then see the "password:" prompt and the script will continue on.  If I telnet manually into the switch, all that is needed is "enter", and not "control+enter".

Does anybody know how I would send a "control+enter" through this application?  I have tried "^\m" "\^\m" but it simply prints those characters before the carriage return.

Or, does anybody know of another windows based scriptable utility that can be run standalone and not be installed?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007

Commented:
You might try this:

@echo off

if exist CtlEnt.txt del CtlEnt.txt >NUL

echo e 100 a>_temp.txt
echo r cx>>_temp.txt
echo 1 >>_temp.txt
echo n CtlEnt.txt>>_temp.txt
echo w>>_temp.txt
echo q>>_temp.txt

type _temp.txt|debug

echo 1.2.3.4 23>script.txt
echo WAIT "login:">>script.txt
echo SEND "administrator">>script.txt
copy /b script.txt+CtlEnt.txt script.txt
echo WAIT "Password:">>script.txt
echo SEND "mypassword">>script.txt
copy /b script.txt+CtlEnt.txt script.txt
echo WAIT ">">>script.txt
echo SEND "my commands">>script.txt

del _temp.txt>NUL
del CtlEnt.txt>NUL
echo script.txt contains script

The script creates a file named CtlEnt.txt via debug. The file contains a single character, a CTRL-ENTER (LF) 0x0a. I believe this is the character you want. It then generates a script and when the CTRL-ENTER is required the script file is appended with the CtlEnt.txt file.

Good Luck,
Steve
Top Expert 2007
Commented:
This version gets rid of the noise from the batch file:

@echo off

if exist CtlEnt.txt del CtlEnt.txt >NUL

echo e 100 a>_temp.txt
echo r cx>>_temp.txt
echo 1 >>_temp.txt
echo n CtlEnt.txt>>_temp.txt
echo w>>_temp.txt
echo q>>_temp.txt

type _temp.txt|debug>NUL

echo 1.2.3.4 23>script.txt
echo WAIT "login:">>script.txt
echo SEND "administrator">>script.txt
copy /b script.txt+CtlEnt.txt script.txt>NUL
echo WAIT "Password:">>script.txt
echo SEND "mypassword">>script.txt
copy /b script.txt+CtlEnt.txt script.txt>NUL
echo WAIT ">">>script.txt
echo SEND "my commands">>script.txt

del _temp.txt>NUL
del CtlEnt.txt>NUL
echo script.txt contains script

Commented:
I'm having this same problem though i am confused how you implement this change? Do you create a new bat file with this script in?
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Top Expert 2007

Commented:
Yes, then change the values for your processing, i.e. IP address. The results will be in script.txt

Commented:
thanks for the reply; however it seems to be sending the login twice although the script.txt it generated looks fine.
Top Expert 2007

Commented:
Curious...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial