::REM ------------------- Begin sample batch script ------------------------ ::REM Sample batch programming script Serverup.cmd ::REM (C)2006 John D. Seaman, Copylefted under terms of the GNU/GPL ::REM by John D. Seaman, www.japan-page.net/batch @echo off cls echo. echo. echo _____ __ __ echo ^/ ___^/___ ______ _____ _____^/ ^/ ^/ ^/___ echo ^\__ \^/ _ \^/ ___^/ ^| ^/ ^/ _ \^/ ___^/ ^/ ^/ ^/ __ \ echo ___^/ ^/ __^/ ^/ ^| ^|^/ ^/ __^/ ^/ ^/ ^/_^/ ^/ ^/_^/ ^/ echo ^/____^/\___^/_^/ ^|___^/\___^/_^/ \____^/ .___^/ echo ^/_^/ echo S e r v e r U p V e r i f i c a t i o n S c r i p t 0.02a echo. ::REM ASCII art generator on the web @ http://www.network-science.de/ascii/ ::REM ------------------ Begin user configuration -------------------------------------- ::REM Set variables set _log=log.txt set _frm=serverMon@yourdomain.com set _too=cellphone#@yourwirelesscarrier.com set _hst=smtp.server.com ::REM Initialize the alert variable. set _alert=0 ::REM I look for a specific page (ismyserverup.asp) because I use a blog and didn't choose to embed my test string "smeg". set _page=ismyserverup.asp set _trigger=smeg ::REM Generate the servers.ini file. Add or remove FQDN lines for each web server you want to check. ::REM You need at least one entry, but this utility will loop through as many lines as you wish to add. echo www.mydomain.com>servers.ini echo home.mydomain.com>>servers.ini echo alternate.mydomain.com>>servers.ini ::REM ------------------ End user configuration -------------------------------------- ::REM Create the log file echo.>%_log% echo Server test script executed on %computername% on %date% at %time%. >>%_log% echo.>>%_log% echo.>>%_log% ::REM Do it already... for /f %%i in (servers.ini) do call :doCheck %%i echo. echo Finished. sleep 5 ::REM Check the alert status if "%_alert%" == "1" (goto :blastSMTP) echo Completed without errors. echo Completed without errors.>>%_log% goto :EOF :blastSMTP ::REM Send out the SMTP alert set _sbj="Alert: One or more errors found, web services are down." echo. echo.>>%_log% echo Errors detected, e.mail sent. echo Errors detected, e.mail sent.>>%_log% bmail -f %_frm% -s %_hst% -t %_too% -a %_sbj% -m %_log% -d goto :EOF ::REM ------------ F U N C T I O N S ----------------------------- :doCheck ::REM Do it already! ::REM Get content from the web server tinyget -d %1 /%_page% >_out.txt ::REM Check the content type _out.txt | find "%_trigger%" goto :result%ERRORLEVEL% :result0 ::REM Server is echo Server %1 is up, no problems detected. echo Server %1 is up, no problems detected.>>%_log% echo.>>%_log% goto :EOF :result1 ::REM Server is down echo The server %1 was not available. echo ALERT: The server %1 was not available !! >>%_log% echo.>>%_log% set _alert=1 goto :EOF :EOF ::REM ------------------- End sample batch script ------------------------