Looking for Windows batch file which will telnet to one IP address, automatically provide username & password which is specified in batch file, execute some series of commands and exit from telnet.
@echo off
SET username=abc
SET password=xyz@1234
SET servername=192.168.1.40
echo user %username%> telnetcmd.dat
echo %password%>> telnetcmd.dat
echo adbd^& >> telnetcmd.dat
echo exit>> telnetcmd.dat
telnet %servername% < telnetcmd.dat
del telnetcmd.dat
Here I am trying to do telnet to IP with username & password. After successful login it should execute adbc& (This will run necessary service in background) command and exit command. Once I complete this batch file and if I check adbc service running on server or not it is showing not running on server.
Output I am getting after completion of batch file.
Welcome to Microsoft Telnet Client
Escape Character is 'CTRL+]'
c:\Users\vshah\Desktop>
Expected Output:
root@pqrs:/ # ps | grep adbd
shell 31899 31828 1348 148 ffffffff 00013348 S adbd
Actual Output after executing batch file:
root@pqrs:/ # ps | grep adbd
1|root@pqrs:/ #
Kindly help me on this to achieve this scenario.
Thank your very much in advance.
Best Answer
It is not actually a batch, but rather a vbscript, and it uses sleep, so in high latency situations, it easily fail, but I have used the following script to test sending email via telnet