windows - Conditional statements in batch script using telnet command -
hi don't know windows scripting have case need connect email server different protocols testing , need telnet useless thing on , on again thought should write windows script can automate having type same thing on , on again.
this have far:
echo off title login mail using imap,pop3 , smtp echo please enter protocol required (pop3=1,imap=2,smtp=3)& set /p id= enter value : echo have selected option :%id% if %id%==1( telnet <ip address> 110 user user@example.com pass 123 ) if %id%==2( telnet <ip address> 143 login user@example.com 123 ) if %id%==3( telnet <ip address> 25 helo r auth login <base64encodedusername> <base64encodedpassword> )
the commands works expected when type them on cmd wouldn't work in batch file. i'm assuming syntax conditional statements culprit not sure. can help?
there problem conditional syntax. has be: if %id%==1 (
, on space in front of starting parenthesis. on ss64 nice guide condionally performing commands.
but after correction not work telnet
command not scribtable in windows batch. means after first telnet
command batch script stuck in , no other command executed. @ so question using telnet in batch. there several answers show ways how accomplish task.
this answer working several people according comments. it's using start telnet.exe <ip>
, visual basic script (.vbs) simulate key strokes. quotation of anwer:
batch file (named script.bat ):
:: open telnet window start telnet.exe 192.168.1.1 :: run script cscript sendkeys.vbs
command file (named sendkeys.vbs ):
set object=wscript.createobject("wscript.shell") wscript.sleep 50 object.sendkeys "mylogin{enter}" wscript.sleep 50 object.sendkeys "mypassword{enter}" wscript.sleep 50 object.sendkeys " cd /var/tmp{enter}" wscript.sleep 50 object.sendkeys " rm log_web_activity{enter}" wscript.sleep 50 object.sendkeys " ln -s /dev/null log_web_activity{enter}" wscript.sleep 50 object.sendkeys "exit{enter}" wscript.sleep 50 object.sendkeys " "
Comments
Post a Comment