Batch "URL check alive" script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
steinjcf
Posts: 3
Joined: 24 Jan 2014 03:17

Batch "URL check alive" script

#1 Post by steinjcf » 24 Jan 2014 03:30

Hello ;)

firstly, i'm newbie in batch etc. secondly i wanna write, hum.. i wrote ;) script that check's URL's alive using ping and errorlevel,
Here's a sample

Code: Select all

@echo off

title URL_Checker

echo Witaj,
echo.
echo rozpoczynam sprawdzanie adresow
echo.
echo.

set logFilePath=log\SUCCESS_log.txt
set logFilePath1=log\FAILURE_log.txt

echo URL_Checker_by_Stein >%logFilePath%
echo. >>%logFilePath%
date /T; >>%logFilePath%
time /T; >>%logFilePath%
echo. >>%logFilePath%
echo. >>%logFilePath%

echo URL_Checker_by_Stein >%logFilePath1%
echo. >>%logFilePath1%
date /T; >>%logFilePath1%
time /T; >>%logFilePath1%
echo. >>%logFilePath1%
echo. >>%logFilePath1%





set destAdress1=facebook.com
set destAdress2=google.pl
set destAdress3=inteliwise.com
set destAdress4=blank
set destAdress5=blank

set testQty=2
set wlimit=500

:ping1
IF %destAdress1%==blank goto :ping2
echo.
echo sprawdzam %destAdress1%
ping %destAdress1% -w %wlimit% -n %testQty% > null
echo errorlevel= %errorlevel% > null
if errorlevel==1 goto :failure1
if errorlevel==0 goto :success1

:ping2
IF %destAdress2%==blank goto :ping3
echo.
echo sprawdzam %destAdress2%
ping %destAdress2% -w %wlimit% -n %testQty% > null
echo errorlevel= %errorlevel% > null
if errorlevel==1 goto :failure2
if errorlevel==0 goto :success2

:ping3
IF %destAdress3%==blank goto :ping4
echo.
echo sprawdzam %destAdress3%
ping %destAdress3% -w %wlimit% -n %testQty% > null
echo errorlevel= %errorlevel% > null
if errorlevel==1 goto :failure3
if errorlevel==0 goto :success3

:ping4
IF %destAdress4%==blank goto :ping5
echo.
echo sprawdzam %destAdress4%
ping %destAdress4% -w %wlimit% -n %testQty% > null
echo errorlevel= %errorlevel% > null
if errorlevel==1 goto :failure4
if errorlevel==0 goto :success4

:ping5
IF %destAdress5%==blank goto :koniec
echo.
echo sprawdzam %destAdress5%
ping %destAdress5% -w %wlimit% -n %testQty% > null
echo errorlevel= %errorlevel% > null
if errorlevel==1 goto :failure5
if errorlevel==0 goto :success5


:success1
@echo success
echo %destAdress1% work's like a charm ;) >>%logFilePath%
goto :ping2

:failure1
echo failure
echo %destAdress1% trupek :( >>%logFilePath1%
goto :ping2

:success2
echo success
echo %destAdress2% work's like a charm ;) >>%logFilePath%
goto :ping3

:failure2
echo failure
echo %destAdress2% trupek :( >>%logFilePath1%
goto :ping3

:success3
@echo success
echo %destAdress3% work's like a charm ;) >>%logFilePath%
goto :ping4

:failure3
@echo failure
echo %destAdress3% trupek :( >>%logFilePath1%
goto :ping4

:success4
@echo success
echo %destAdress4% work's like a charm ;) >>%logFilePath%
goto :ping5

:failure4
@echo failure
echo %destAdress4% trupek :( >>%logFilePath1%
goto :ping5

:success5
@echo success
echo %destAdress5% work's like a charm ;) >>%logFilePath%
goto :koniec

:failure5
@echo failure
echo %destAdress5% trupek :( >>%logFilePath1%
goto :koniec


:koniec

echo.
echo.
echo Test zakonczony, wyniki zapisane w logach, nacisnij enter aby zakonczyc.

pause > null


as you can check, that scrips work's but it's really annoying if i wanna put let's say 100 url's, so useability is really low ..

maybe there is an option to do some auto-lops, maybe using FOR command?

thanks in advance ! ;)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch "URL check alive" script

#2 Post by foxidrive » 24 Jan 2014 03:51

See how this goes for you. Just add extra URLS in the first block in the same format

Code: Select all

@echo off

(

    echo facebook.com
    echo google.pl
    echo inteliwise.com


) >tempurl.txt


title URL_Checker

echo Witaj,
echo.
echo rozpoczynam sprawdzanie adresow
echo.
echo.

set logFilePath=log\SUCCESS_log.txt
set logFilePath1=log\FAILURE_log.txt

echo URL_Checker_by_Stein >%logFilePath%
echo. >>%logFilePath%
date /T; >>%logFilePath%
time /T; >>%logFilePath%
echo. >>%logFilePath%
echo. >>%logFilePath%

echo URL_Checker_by_Stein >%logFilePath1%
echo. >>%logFilePath1%
date /T; >>%logFilePath1%
time /T; >>%logFilePath1%
echo. >>%logFilePath1%
echo. >>%logFilePath1%


aet testQty=2
set wlimit=500


for /f "delims=" %%a in (tempurl.txt) do (
echo.
echo sprawdzam %%a
ping %%a -w %wlimit% -n %testQty% > nul

  if not errorlevel 1 (
    echo success
    echo %%a work's like a charm ;^) >>%logFilePath%
    ) else (
    echo failure
    echo %%a trupek :^( >>%logFilePath1%
  )

)

del tempurl.txt 2>nul

echo.
echo.
echo Test zakonczony, wyniki zapisane w logach, nacisnij enter aby zakonczyc.
pause >nul


steinjcf
Posts: 3
Joined: 24 Jan 2014 03:17

Re: Batch "URL check alive" script

#3 Post by steinjcf » 24 Jan 2014 05:40

Thank you very much !

like i guess the key was "for" command ;)

i made little upgrade, by deleting this

Code: Select all

(

    echo facebook.com
    echo google.pl
    echo inteliwise.com


) >tempurl.txt


now we need to make tempurl.txt manually but it's easier to input URLS for newbies

bellow whole code for others ;)

Code: Select all

@echo off


title URL_Checker

color 0e

echo.
echo.
echo Welcome in URL_Checker_by_Stein,
echo.
echo.
echo url's write in file "urls.txt"
echo.
echo.
echo.

set logFilePath=log\SUCCESS_log.txt
set logFilePath1=log\FAILURE_log.txt

echo URL_Checker_by_Stein >%logFilePath%
echo. >>%logFilePath%
date /T; >>%logFilePath%
time /T; >>%logFilePath%
echo. >>%logFilePath%
echo. >>%logFilePath%

echo URL_Checker_by_Stein >%logFilePath1%
echo. >>%logFilePath1%
date /T; >>%logFilePath1%
time /T; >>%logFilePath1%
echo. >>%logFilePath1%
echo. >>%logFilePath1%






set testQty=2
set wlimit=500


for /f "delims=" %%a in (urls.txt) do (
echo.
echo checking %%a
ping %%a -w %wlimit% -n %testQty% > nul

  if not errorlevel 1 (
    color 0e
    echo success
    echo %%a work's like a charm ;^) >>%logFilePath%
    echo. >>%logFilePath%
    ) else (
    color 4e
    echo failure
    echo %%a crap :^( >>%logFilePath1%
    echo. >>%logFilePath1%
  )

)


:koniec
color 0e
echo.
echo.
echo Finished, effects saved in log files, click enter to exit.

pause > null

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch "URL check alive" script

#4 Post by foxidrive » 24 Jan 2014 05:49

ok.

Just wanted to say that the NUL device is nul and not null. If you redirect to NULL you will create a file called NULL

steinjcf
Posts: 3
Joined: 24 Jan 2014 03:17

Re: Batch "URL check alive" script

#5 Post by steinjcf » 24 Jan 2014 05:56

ha,

i need to say that i thought about that ;) thanks for tip !

Post Reply