?
Solved

Batch file and telnet commands

Posted on 2013-11-07
1
Medium Priority
?
5,593 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Viewers will learn how to properly install and use Secure Shell (SSH) to work on projects or homework remotely. Download Secure Shell: Follow basic installation instructions: Open Secure Shell and use "Quick Connect" to enter credentials includi…
Starting up a Project
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

765 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