Solved

Batch file and telnet commands

Posted on 2013-11-07
1
5,091 Views
Last Modified: 2013-11-15
I need some help with this. I have a process that monitors a POE camera device that sometimes has issues. Once an issue is detected the program will run the below batch file. This works great when I'm logged into the server (and the screen isn't locked). However when the screen is locked it doesn't run successfully. When I log into the machine again, I see a few telnet session that have been opened, and it stopped at username (basically it's like the telnetfe33.vbs script couldn't run). I believe the issue is that the server is locked when I leave a session and it can't send the keys. Does anyone know of a way to accomplish this without having to have the machine always open and unlocked? I was going to try plink, but didn't know if that would work either, and how to accomplish that goal. Basically I'm trying to reset a port on the switch which reboots the camera.

Batch file to start the telnet session
start telnet.exe 192.168.0.3
cscript c:\jobs\telnetfe33.vbs

File telnetfe33.vbs
set OBJECT=WScript.CreateObject("WScript.Shell")
WScript.sleep 50
OBJECT.SendKeys "myusername{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "mypassword{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "en{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "myelevatedpassword{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "conf t{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "int fa0/33{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "shutdown{ENTER}"
WScript.sleep 30000
OBJECT.SendKeys "no shutdown{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "exit{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "exit{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "exit{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "exit{ENTER}"
0
Comment
Question by:jasonmohan
1 Comment
 
LVL 36

Accepted Solution

by:
ArneLovius earned 500 total points
ID: 39633080
As you are only using "timed waits" rather than "expects", I would guess that you are simply hitting  a timeout...

I would suggest looking at an alternative method that can use an "expect" method.

You might find this useful http://support.moonpoint.com/downloads/windows/network/Telnet/tst10.php

You can then have a script along the lines of

hostname
WAIT "login"
SEND "username"
WAIT "Password"
SEND "password\m"
WAIT ">"
SEND "en"
WAIT "Password"
SEND "enablepassword\m"
WAIT "#"
SEND "conf t\m"
WAIT "#"
SEND "int fa0/33"
WAIT "#"
SEND "shut\m"
WAIT "#"
SEND "no shut\m"
WAIT "#"
SEND "exit\m"
WAIT "#"
SEND "exit\m"
WAIT "#"
SEND "exit\m"

Open in new window


or you could use plink
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Creating an OSPF network that automatically (dynamically) reroutes network traffic over other connections to prevent network downtime.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

706 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

16 Experts available now in Live!

Get 1:1 Help Now