| 1. |
Solve : Delete lines in txt files that contains an STRING or are BLANK.? |
|
Answer» Hello, Not sure how you have your pings setup, but you might want to build an outer loop to the snippet so you can iterate your multiple IP addresses or names. Thank you for response. I think I should have said from start that I am an beginer in batch files. I tried to use your code with my ping but don't works. I think I didn't used properly your code. Any sugestion of how to set up my pings is welcomed also. My pings setup now looks like this: Code: [Select]del ping.log date/t >>ping.log time/t >>ping.log ping -n 2 server1 >> ping.log ping -n 2 server2 >> ping.log Because I use it to ping nore than 25 servers at the time, the result log is very log and not easy to read. Sow I only want to make it easy to read and for that I want to cut out non needed lines. An DREAM would be, if its possible, to have an result like: Date Time SERVER1 RESPONDING SERVER2 NOT RESPONDING SERVER3 RESPONDING SERVER4 NOT RESPONDING Code: [Select]@echo off REM echo your server urls to a list REM first one uses >, the the rest use >> REM I only show 3 here for the sake REM of brevity echo www.google.com > servers.list echo www.bbc.co.uk >> servers.list echo www.yahoo-ht3.akadns.net >> servers.list REM now ping them & act according to REM the errorlevel returned for /f %%S in (servers.list) do ( ping %%S>nul if %errorlevel% EQU 0 ( echo %%S RESPONDING ) else ( echo %%S NOT RESPONDING ) ) Quote from: Dias de verano on December 13, 2008, 02:08:32 AM Code: [Select]@echo off Hello, Sorry for not respondig, but I didn't had ACCES to an computer for several days. Dias de verano, u'r code is almost perfect. I added only ECHO for having an result.txt but it seems to be an problem at ERRORLEVEL. No MATTER of pinged host the response is always RESPONDING. Here is the code i used, I cut off the messages for space: Code: [Select]@echo off echo 123.123.123.123 > servers.list echo www.bbc.co.uk >> servers.list echo www.yahoo-ht3.akadns.net >> servers.list for /f %%S in (servers.list) do ( ping %%S>nul if %errorlevel% EQU 0 ( echo %%S RESPONDING >> result.txt ) else ( echo %%S NOT RESPONDING >> result.txt ) ) My result.txt 123.123.123.123 RESPONDING www.bbc.co.uk RESPONDING www.yahoo-ht3.akadns.net RESPONDING Sorry, I made an oversight. @echo off setlocal enabledelayedexpansion REM echo your server urls to a list REM first one uses >, the the rest use >> REM I only show 3 here for the sake REM of brevity echo www.google.com > servers.list echo www.bbc.co.uk >> servers.list echo www.yahoo-ht3.akadns.net >> servers.list REM now ping them & act according to REM the errorlevel returned for /f %%S in (servers.list) do ( ping %%S>nul if !errorlevel! EQU 0 ( echo %%S RESPONDING>>result.txt ) else ( echo %%S NOT RESPONDING>>result.txt ) ) EXCELENT. THANK YOU VERY MUCH. |
|