Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

how to telnet using batch file pls help

Jul 12, 2007 12:29AM PDT

hi i am currently trying to use a batch file to telnet to an host and
do a sh cdp neigh > hi.txt

i tryed this:
telnet 111.111.111.111
sh cdp neigh > hi.txt
however it does not work as the sh cdp neigh >hi.exe
only execute after i exit from the telnet is there anyway to solve this please help thx

Discussion is locked

- Collapse -
add on
Jul 12, 2007 12:31AM PDT

sry let me rephase the subject it should be

how to telnet with authentication using batch file help

so after the telnet i inpput the passwork pls help thx

- Collapse -
Links only.
Jul 12, 2007 12:47AM PDT
- Collapse -
NTAutoScript
Dec 20, 2008 11:33PM PST

Use NTAutoScript
it can work well for you.
email zhitenglin@163.com
i send you a copy to have a try.

- Collapse -
Automating telnet
Nov 9, 2011 8:57AM PST

I researched a lot about it but using a batch file it is not possible. You can use a VBS in Windows to control telnet sessions. A piece of code has been pasted below for your help.
Copy this and paste it into a vbs file. Works well for me. Happy You can add you commands in the whole script according to your convenience.


Set cloner = CreateObject("WScript.Shell")
cloner.run"cmd"
WScript.Sleep 500

cloner.SendKeys"telnet 192.168.1.1"
cloner.SendKeys("{Enter}")
WScript.Sleep 500

cloner.SendKeys"admin"
cloner.SendKeys("{Enter}")
WScript.Sleep 500

cloner.SendKeys"password"
cloner.SendKeys("{Enter}")
WScript.Sleep 500

cloner.SendKeys"quit"
cloner.SendKeys("{Enter}")

- Collapse -
output of results
Nov 18, 2011 9:28AM PST

how can output the result to txt file please?

- Collapse -
Re: outputting to textfile
Jan 30, 2012 5:19PM PST

Run wscript.exe from the command prompt with output redirection to a text file. Redirecting output to a file probably was present already in MS DOS 1.0, back in 1980.

wscript myscript.vbs > mytextfile.txt

Use quotes around filenames where applicable (if there are spaces in it).

Kees

- Collapse -
hi kees capture telnet seesion
Feb 2, 2012 12:20AM PST

hi kees

by above line i am not able to understand exactly.could you plz explain me brefly.
my requirement is i should enter in to router automatically and run one command automatically (ex sh int f0/0/0). the result data should get captured in to file.

plz explain me brefly (by giving direct code)

thx u
mahe

- Collapse -
Re: example
Feb 2, 2012 6:54PM PST

The code I gave is the code for the command interpreter (type it in or make it a batchfile).
wscript myscript.vbs > mytextfile.txt

That's the way to put the output of the vbs-script file in a textfile. And that's what the question was about. In the context of the thread, which was writing a script to run telnet and have it execute some commands.

Kees

- Collapse -
telnet to router and capture the data
Jan 30, 2012 4:57PM PST

hi
the above code is working fine,
i wan to capture the data to a particular file after telnet made is ther any code for thet .
pleae help me.

- Collapse -
Re: capture to file
Jan 31, 2012 6:07PM PST

See my post above (Re: outputting to text file) about output redirection.

Kees

- Collapse -
HI kees system shoushutdown
Feb 2, 2012 9:25PM PST

Hi all, i am looking for a script where i can shutdown all the pcs in a lan in an organization when the system is idle for more than 2 hours through group ploicy. please provide any batch file or shell script or vbs script to run from gp. if any know it plz explain me it in brefly (steps) thank you

i am using 2003 server sp2 os in my server.

- Collapse -
That's quite something else.
Feb 2, 2012 9:55PM PST