| 1. |
Solve : Need help with batch file calling text contents into batch commands? |
|
Answer» Please help as i would like to make the following 1. test.txt (NO SPACES) With great thanks. Added knowledge Actually what i needed is shown below. Sorry for not putting it clearly 1. ipadd.txt ip1=192.168.100.232 ip2=192.168.100.233 2. ping.bat @echo off cls ping %ip1% pause 3. Console output should be Pinging 192.168.100.232 with 32 bytes of data: Reply from 192.168.100.232: bytes=32 time<1ms TTL=255 Reply from 192.168.100.232: bytes=32 time<1ms TTL=255 Reply from 192.168.100.232: bytes=32 time<1ms TTL=255 Reply from 192.168.100.232: bytes=32 time<1ms TTL=255 Ping statistics for 192.168.100.232: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss) Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms Tried to research but still couldn't find the correct method Well, all you need to do now is edit your batch file. The most obvious problem is that you have called your batch file the name of a system command, and in this case ping.bat will call itself again and again. Call this IPPing.bat or something simpler like IP.bat Code: [Select]@echo off for /f "tokens=2 delims==" %%A in (ipadd.txt) do ( cls ping %%A pause )Quote from: foxidrive on October 25, 2013, 05:20:44 AM The most obvious problem is that you have called your batch file the name of a system command, and in this case ping.bat will call itself again and again. it works for the first line of the ipadd.txt how do i ping to the 2nd line of the ipadd.txt ip1=192.168.100.232 ip2=192.168.100.233 sorry for asking noobie QUESTIONS It pings the first IP address, Then you press any key and it will ping the second IP address and then when you press any key it will finally quit.Below are my scripts currently For Main Bat file named: ServerTest.bat Code: [Select]@echo off cls :start echo *************************************************** echo ********* Please Select The Server You WANT Ping ******** echo *************************************************** echo. echo 1. To Ping Server 1 echo 2. To Ping Server 2 echo. echo 0. To Quit echo. set /p choice="Enter your choice: " if "%choice%"=="1" goto Server1 if "%choice%"=="2" goto Server2 if "%choice%"=="0" exit echo Invalid choice: %choice% echo. pause cls goto start :Server1 cls C:\"SScript"\"Server1" goto :start echo. :Server2 cls C:\"SScript"\"Server2" goto :start echo. exit For another bat file that was called from main as shown below; Server1.bat Code: [Select]@echo off echo. [color=RED]for /f "tokens=2 delims==" %%A in (tsip.txt) do ( cls ping %%A[/color] goto :start ) :start echo. echo 1. If Reply. Continue Script echo. echo 2. Go Back to Main Menu echo. echo 0. To Quit echo. set /p choice="Enter your choice: " if "%choice%"=="1" goto Script if "%choice%"=="2" goto MainMenu if "%choice%"=="0" exit echo Invalid choice: %choice% echo. pause cls goto start :Script Start telnet.exe [color=red]192.168.100.232[/color] cscript sendkeys.vbs echo. call "ServerTest.bat" :MainMenu cls start C:\"SScript"\"ServerTest.bat" :exit exit I want to avoid using many server1.bat, server2.bat, etc... So thats why i wanted to know instead of creating so many server bat files with different IP address. Is there a way of calling those highlighted in red from text file based on the specific lines? IPadd.txt Code: [Select]IP1=192.168.100.232 IP2=192.168.100.233 IP3=192.168.100.234 Appreciate with all the information given =)for /f "delims=" %%A in (IPadd.txt) do call server1.bat "%%A" then change all INSTANCES of the ip address stored in IPadd.txt to %~1. Just make sure at the end you have an exit /b |
|