Solved

Batch file and telnet commands

Posted on 2013-11-07
1
5,281 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 37

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 SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

A short article about a problem I had getting the GPS LocationListener working.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

786 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