Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using wscript to batch telnet...

Status
Not open for further replies.

dwcasey

MIS
Oct 31, 2002
179
US
I have to telnet to a lot of hosts and was able to use the below script for automating a single telnet. How can I combine this with a loop of sorts to read through a list of hostnames and open a telnet to each host?

The "catch" is that I have to telnet to two boxes before I can telnet out to the "world". This client has a DMZ server of sorts, then their server, then the remote site machines.

----------------------

@ECHO OFF
:: :::::::::::::::::::::::::::::::::::::::::::::
:: temp_SendKeys.VBS will contain the "commands"
ECHO.set handler=WScript.CreateObject("WScript.Shell")>temp_SendKeys.VBS
ECHO.WScript.sleep 1500 >>temp_SendKeys.VBS


:: :::::::::::::::::::::::::::::::::::::::::::::
:: Open Connection To DMZ
ECHO.handler.SendKeys "open 1.2.3.4~" >>temp_SendKeys.VBS
ECHO.WScript.sleep 1500 >>temp_SendKeys.VBS


:: :::::::::::::::::::::::::::::::::::::::::::::
:: Send My Login Name
ECHO.handler.SendKeys "user01~" >>temp_SendKeys.VBS
ECHO.WScript.sleep 1500 >>temp_SendKeys.VBS
:: Send My Password
ECHO.handler.SendKeys "mypass~" >>temp_SendKeys.VBS
ECHO.WScript.sleep 1500 >>temp_SendKeys.VBS


:: :::::::::::::::::::::::::::::::::::::::::::::
:: Send Stuff to be done
ECHO.handler.SendKeys "uname -a~" >>temp_SendKeys.VBS
ECHO.WScript.sleep 1500 >>temp_SendKeys.VBS

:: :::::::::::::::::::::::::::::::::::::::::::::
:: Open Connection To Customer server
ECHO.handler.SendKeys "tn dmzsrv01~" >>temp_SendKeys.VBS
ECHO.WScript.sleep 1500 >>temp_SendKeys.VBS

:: :::::::::::::::::::::::::::::::::::::::::::::
:: Send My Login Name
ECHO.handler.SendKeys "user01~" >>temp_SendKeys.VBS
ECHO.WScript.sleep 1500 >>temp_SendKeys.VBS
:: Send My Password
ECHO.handler.SendKeys "mypass~" >>temp_SendKeys.VBS
ECHO.WScript.sleep 1500 >>temp_SendKeys.VBS

:: :::::::::::::::::::::::::::::::::::::::::::::
:: Send Stuff to be done
ECHO.handler.SendKeys "uname -a~" >>temp_SendKeys.VBS
ECHO.handler.SendKeys "export TMOUT=0~" >>temp_SendKeys.VBS
ECHO.WScript.sleep 1500 >>temp_SendKeys.VBS

:: :::::::::::::::::::::::::::::::::::::::::::::
:: Open Connection To REMOTE Customer site
ECHO.handler.SendKeys "tn exthost01~" >>temp_SendKeys.VBS
ECHO.WScript.sleep 1500 >>temp_SendKeys.VBS

:: :::::::::::::::::::::::::::::::::::::::::::::
:: Logout
:: ECHO.handler.SendKeys "exit~" >>temp_SendKeys.VBS
:: ECHO.WScript.sleep 1250 >>temp_SendKeys.VBS
:: ECHO.handler.SendKeys " " >>temp_SendKeys.VBS
:: ECHO.WScript.sleep 1250 >>temp_SendKeys.VBS
:: ECHO.handler.SendKeys "quit~" >>temp_SendKeys.VBS
:: ECHO.WScript.sleep 1250 >>temp_SendKeys.VBS


:: Open a Telnet Windows
start telnet.EXE

:: Run the script
cscript//nologo temp_SendKeys.VBS

:: Delete the temporary file
DEL temp_SendKeys.VBS

quit
exit
 
Take a look at SysInternals PSEXEC. Easily scriptable adn lets you run code remotely on another machine.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Ok, I forgot to mention, or I was not clear. I am telnet`ing from my XP Pro client to an AIX server, to another AIX server, then finally out to a remote site that is an AIX server.
 
Sorry I don't know anything about AIX. Would not know what would be possible, but I assume vbscript is out of the picture since that is a MS technology.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
You might peruse thread329-1397077 for ideas.

I'd forget about SendKeys entirely (despite the thread title above). It's terribly unreliable because other windows can take focus at any time, leaving you up a creek. I'd throw that BAT/CMD file as far as I could too. Why not just write a CScript to do the job and call it good?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top