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

Posted on 2006-04-11
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

    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 82

    Accepted Solution

    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
    LVL 9

    Assisted Solution

    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.
    LVL 14

    Expert Comment

    The suggestion of SteveGTR (http:#16433328) would probably work if you use netcat instead of telnet:
    LVL 95

    Assisted Solution

    by:Lee W, MVP
    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.
    LVL 3

    Author Comment

    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

    LVL 4

    Expert Comment

    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

    > 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 :)
    LVL 4

    Expert Comment

    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

    Good point. No offense implied :)

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT ( The crux of this batch f…
    Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now