@echo off rem ######################################################################## rem ### rem ### runtimecheck.cmd rem ### version 0.0.2 rem ### by Mark Wolfgruber rem ### rem ### Example Programm to Demonstrate getting the runtime from a rem ### script / programm or command rem ### rem ### Please, only use during one Day or modify the script! rem ### rem ######################################################################## :vars set __debug_file__=runtimecheck.debug.tail set __output_file__=runtimecheck.out.tail set __result_file__=runtimecheck.result.tail echo %date% %time% ### Start of Script ### echo %date% %time% ## command/programme output-file: %__output_file__% rem DEBUG on or off set it into the enviroment or in the following lines rem if "%__debug__%"="" set __debug__=off if "%__debug__%"=="" set __debug__=on if "%__debug__%"=="on" ( echo %date% %time% debug is on, debugfile: %__debug_file__% echo %date% %time% %date% %time% ### Start debug of Script ### > %__debug_file__% ) :check_network rem if no ping to localhost goto error rem Remark if you don't need a network check rem you may use "ping 127.0.0.1 -n 1" or "ping localhost -n 1" ping localhost -n 1 > nul && echo ping to localhost OK >> %__debug_file__% || echo ERROR no ping to localhost && goto end :main rem ### Example PING rem DEFINE here the command you want to monitor set __command__=ping rem repeat the command set __repeat__=3 rem set the enviroment for your command/programm set __ip__=192.168.2.1 set __command_options__=%__ip__% -w 500 -n 1 FOR /L %%a IN (1,1,%__repeat__%) DO call :function_start_programm rem DEFINE other parameters set __ip__=192.168.2.2 set __command_options__=%__ip__% -w 5000 -n 2 FOR /L %%a IN (1,1,%__repeat__%) DO call :function_start_programm rem ### Example NSLOOKUP rem DEFINE here the command you want to monitor set __command__=nslookup rem repeat the command set __repeat__=3 rem set the enviroment for your command/programm set __dnsname__=www.google.de set __command_options__=%__dnsname__% FOR /L %%a IN (1,1,%__repeat__%) DO call :function_start_programm rem DEFINE other parameters set __ip__=209.85.129.147 set __command_options__=%__ip__% FOR /L %%a IN (1,1,%__repeat__%) DO call :function_start_programm goto end rem ### Section of Functions ### :function_start_programm if "%__debug__%"=="on" echo %date% %time% # %__command__% %__command_options__% >> %__debug_file__% rem save time before running the command call :function_time_now_in_hun set __starttime__=%__a_time_in_hun__% rem here start the programm command %__command__% %__command_options__% >> %__output_file__% 2>&1 rem save time after running the command call :function_time_now_in_hun set __endtime__=%__a_time_in_hun__% rem calculate running time set /a __runtime_in_hun__=(%__endtime__% - %__starttime__%) set /a __runtime_sec__=%__runtime_in_hun__%/100 set /a __runtime_hun__=%__runtime_in_hun__% - (%__runtime_sec__% * 100) set __runtime__=%__runtime_sec__%,%__runtime_hun__% if "%__debug__%"=="on" echo %date% %time% Runtime: %__runtime__% s [ %__command__% %__command_options__% ] >> %__debug_file__% echo %date% %time% Runtime: %__runtime__% s [ %__command__% %__command_options__% ] echo %date% %time% Runtime: %__runtime__% s [ %__command__% %__command_options__% ] >> %__result_file__% goto :EOF :function_time_now_in_hun setlocal FOR /F " usebackq tokens=1,2,3,4,* delims=:, " %%a IN (`echo %time%`) DO ( set __f_Hour__=%%a set __f_Min__=%%b set __f_Sec__=%%c set __f_Hun__=%%d ) if "%__debug__%"=="on" echo %date% %time% __f_Hour__ %__f_Hour__% >> %__debug_file__% set __f_num__=%__f_Hour__% call :function_check_number set __f_Hour__=%__f_num__% if "%__debug__%"=="on" echo %date% %time% __f_Min__ %__f_Min__% >> %__debug_file__% set __f_num__=%__f_Min__% call :function_check_number set __f_Min__=%__f_num__% if "%__debug__%"=="on" echo %date% %time% __f_Sec__ %__f_Sec__% >> %__debug_file__% set __f_num__=%__f_Sec__% call :function_check_number set __f_Sec__=%__f_num__% if "%__debug__%"=="on" echo %date% %time% __f_Hun__ %__f_Hun__% >> %__debug_file__% set __f_num__=%__f_Hun__% call :function_check_number set __f_Hun__=%__f_num__% set /a __h_Hour__=%__f_Hour__% * 60 * 60 *100 || echo %__f_Hour__% set /a __h_Min__=%__f_Min__% * 60 *100 || echo %__f_Min__% set /a __h_Sec__=%__f_Sec__% *100 || echo %__f_Sec__% set /a __h_Hun__=%__f_Hun__% + 0 || echo %__f_Hun__% set /a __a_time_in_hun__=%__h_Hour__% + %__h_Min__% + %__h_Sec__% + %__h_Hun__% if "%__debug__%"=="on" echo %date% %time% __a_time_in_hun__(%__a_time_in_hun__%)=%__h_Hour__% + %__h_Min__% + %__h_Sec__% + %__h_Hun__% >> %__debug_file__% endlocal & set __a_time_in_hun__=%__a_time_in_hun__% goto :EOF :function_check_number if "%__debug__%"=="on" echo %date% %time% __f_num__ (1) %__f_num__% >> %__debug_file__% set "__f_num__=%__f_num__:00=0%" if not %__f_num__% EQU 0 if %__f_num__% lss 10 set "__f_num__=%__f_num__:0=%" set /a __f_num__=%__f_num__% + 0 if "%__debug__%"=="on" echo %date% %time% __f_num__ (2) %__f_num__% >> %__debug_file__% goto :EOF :end echo %date% %time% ### END of Script ### rem pause