Name: arul20 Date: May 16, 2005 at 09:36:21 Pacific Subject: Need Help with DOS batch file .. OS: win 2000 CPU/Ram: _
Comment:
Hi I am writing a batch file to automatically run some commands by telnetting to a network device. Everything goes fine until the device asks for input from the user.
E.g "Press any key to continue .. " Or "Press enter to continue .. "
etc
The program then waits for the user input.
So I am forced to manually press the keyboard in order for the batch file to continue.
What I want to know is:
How do I simulate the "Enter" key press in my batch program?
P.S: I did googling today on this subject but they all recommend using the "CON" command with fc command. I am running windows 2000 and my DOS does not support the "CON" command.
I tried out echo.| on commands such as DATE and PAUSE. They worked fine.
However, telnet.exe is a separate program stored in the root directory. It also has its own commands which DOS doesn't recognise. (OPEN, CLOSE .. etc)
I tried out using pipe to telnet but DOS is not able to send any keys to telnet once telnet starts up.
HOW? Is there a way for my batch file to send commands to the telnet program?
If not can I use any other method?
I can maybe use hyperterminal, but the problem I face with hyperterminal is that I need to use the GUI to log off one connection and create a new connction. I want to automate the process so that the program will connnect to several network devices and execute commands.
Whenever there is some common change in setting, I have to log on to each and every device and reconfigure.
What I am trying to do is (cos i'm lazy), I want to create a script to automatically log in to a device and execute commands and then log off and login to the next device .. etc .. all auto.
So using batch file, I am able to start telnet. BUT as I learnt over the past few days, DOS is not optimised for interfacing with devices (thanks ASBO). Thus I cannot execute telnet commands.
So I also tried Hyperterminal. You can prepare text files with the necessary commands before hand and after logging in to a device, let the file run. It is WAY faster than typing by hand all your usual commands.
However, I still have to create a new connection each time. I want to automate that too.
Currently I am researching telnet clients with scripting facility. CRT is popular in my office, however it has limited scripting ability. Then I found TN 3270 yesterday. It seems to be meeting my expectations, but I haven't wrote the script yet.
I suggest looking at some of the other scripting languages such as VB or Perl. Of course, my recomendation is Perl. Take a look at the documentation for this Perl module (Net::Telnet). If you like, I can write the script for you, as long as it's within reason.
Fishmonger, I do not know Perl. You suggested VB also. I'll take a look at it and post the result back in a few days ok?
M2, I also do not know any way to script for HyperTerminal.
However there is another way to speed up your work. Save your usual commands line-by-line in a text file.
click on " Transfer -> Send Text File.. ".
It will load and run all the commands stored in the text file.
Right now I am trying out TN3270 Plus. It is another telnet client but has a good scripting feature also.
What I like about TN3270 is: -You can automate login using scripts -You can execute windows commands -It is possible to have multiple sessions -Logging capabilities
These are some of the stuff I've found so far .. finding more ..
A colleague also suggested VB, so most probably I will be using TN3270 or Visual Basic.
Anyhow, I will post when a new development occurs (or a new problem).
The ftp approach seems a little odd but it might work.
Using an actuall scripting language instead of a macro in a telnet GUI client would be best. There are a number of advantages to using Perl. To name a few, a Perl script would be shorter, cleaner, and easier to write than a VB script (even for someone that is brand new to Perl) as well as being platform independant.
Let me know if you change your mind about using Perl.
Hi guys .. worked on it yesterday and today and it works. I used three files. One Batch file, two script files for the telnet client Thanks for all the help ..
::How it works: :: :: .Batch file is run :: .Batch File runs TN3270 :: .Opens Telnet connection to one address and calls a script (passwords.txt) :: :: .Passwords.txt contains individual commands for each connection :: Besides password, other specific commands such as banner can be specified here :: .TN3270 runs passwords.txt :: .looks up the list of passwords and logs in to the open connection :: .calls the 'common commands script' -> cmds.txt :: :: .Cmds.txt contains the common commands to be executed for ALL the devices :: .TN3270 executes the commands found in cmds.txt :: .execution is passed back to passwords.txt which exits TN3270 :: .excution is passed back to batch file :: :: .Batch file opens the second connection using TN3270 :: .The process is repeated :: .When all devices have been contacted, the batch file closes DOS window.
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE