Link to home
Start Free TrialLog in
Avatar of jasonmohan
jasonmohan

asked on

Batch file and telnet commands

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}"
ASKER CERTIFIED SOLUTION
Avatar of ArneLovius
ArneLovius
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial