Solved

Batch file and telnet commands

Posted on 2013-11-07
1
5,384 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macbook Sierra OS OpenVPN issue 13 153
incorrect syntax near the order by 10 57
Java List 4 39
Automate and generate Azure reports for the following items 3 44
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
A short article about problems I had with the new location API and permissions in Marshmallow
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…

749 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