Need to create a batch file to send "reload" command through telnet

Posted on 2006-04-11
Medium Priority
Last Modified: 2008-01-09
Hi experts,

I've got a problem with our internet router with the internet going slow in the mornings, this is easily fixed with a physical reboot of the router. I'm yet to find the problem. However, there are workers that get in early at about 6.30am to start work, and I get early morning calls if the internet isn't working :) So I was wondering if it's possible to write a batch file that basically opens up a dos window, writes "telnet (the ip address of the internet router) and then after that, logs in with the password, then once dropped into the internet router's prompt, types "enable" and then "reload"

The router is a Cisco 827

This will cause the router to reload its config and bring the internet back up again, saving me an early morning wakeup call :-)

Can anyone give me a hand with this ?


Question by:jaimeklein
LVL 30

Expert Comment

ID: 16433328
Could try and script to feed to telnet. I'm not sure if it will work or not, but it's worth a try:

@echo off

(echo username)>_temp.txt
(echo password)>>_temp.txt
(echo enable)>>_temp.txt
(echo reload)>>_temp.txt
(echo quit)>>_temp.txt

type _temp.txt|telnet

del _temp.txt>NUL

You'd have to encode the username and password in the batch processing.

Good Luck,
LVL 85

Accepted Solution

oBdA earned 672 total points
ID: 16434155
Unfortunately, the native Windows telnet client doesn't support redirection (and I haven't found a third party tool doing this, either).
The only method I've found so far (short of real programming) when I've been looking into this some years ago was the use of Perl.
Here's an introductory example:
Using perl to connect to remote hosts via telnet
Here's the general library:
Jay Rogers > Net-Telnet-3.03 > Net::Telnet
And here's a special library for Cisco:
Joshua Keroes > Net-Telnet-Cisco-1.10 > Net::Telnet::Cisco

Assisted Solution

kfullarton earned 664 total points
ID: 16435000
Try using autoexpect to generate the script that you need.  I use it for automatic backups of Cisco configs which requires login, enable. etc.  Once you've created the script, add it to the task scheduler.

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

LVL 14

Expert Comment

ID: 16439749
The suggestion of SteveGTR (http:#16433328) would probably work if you use netcat instead of telnet: http://www.vulnwatch.org/netcat/
LVL 97

Assisted Solution

by:Lee W, MVP
Lee W, MVP earned 664 total points
ID: 16449941
I suggest you look at the telnet scripting tool.


As others have already said, the windows telnet tools do not support redirection or scripting and no other telnet I've found does either.  This may be your only hope (a colleague of mine found it and used it to do something quite similar with Cisco devices, if I remember correctly)l.

Author Comment

ID: 16458726
Wow you guys are great,

Thanks for all the suggestions. I will look at and try them all and see which one works best when I go back to work in a few days time

Thank you once again


Expert Comment

ID: 16498663
cwwkie is correct.

I've personally abandoned Microsoft Telnet Client whenever possible in favor Netcat as a telnet client myself. (One of the differences being that backspace will always work in Netcat but not in Microsoft Telnet Client. Once you use telnet enough, this difference starts to become important.) Netcat does support redirected input, unlike Microsoft Telnet Client. You need to specify a port with Netcat, however. There is no default port for netcat to connect if none are specified.

SteveGTR, why do you enter in this format:
type _temp.txt|nc 23

When it would be at least as effective to simply enter the following?
nc 23<_temp.txt

Alternatively, you could actually have netcat run batch files against the telnet server (ergo, it takes server output as input and sends server input as its output), but it's not too reliable.
LVL 30

Expert Comment

ID: 16498740
> SteveGTR, why do you enter in this format:
> type _temp.txt|nc 23

> When it would be at least as effective to simply enter the following?
> nc 23<_temp.txt

Caudax , you will find out as you develop your MSDOS skills that there are many ways to accomplish the same task :)

Expert Comment

ID: 16751921
If the author is still present, could we hear a response?

>Caudax , you will find out as you develop your MSDOS skills that there are many ways to accomplish the same task :)

I know there are multiple ways to accomplish the same task. It just struck me as odd that you used type "filename"| to accomplish just about the only purpose there is to <.

On a side note, I've been using DOS for... over 11 years now (though I'm not taking offense at the remark; it just merely struck me as comical, given the circumstances).
LVL 30

Expert Comment

ID: 16752327
Good point. No offense implied :)

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question