diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a265608 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.log.* +*.log \ No newline at end of file diff --git a/windows/network/ping_logger/log/old_logs/dummy b/windows/network/ping_logger/log/old_logs/dummy new file mode 100644 index 0000000..e69de29 diff --git a/windows/network/ping_logger/ping_logger.bat b/windows/network/ping_logger/ping_logger.bat index f2345a0..1adc7d8 100644 --- a/windows/network/ping_logger/ping_logger.bat +++ b/windows/network/ping_logger/ping_logger.bat @@ -1,23 +1,60 @@ @echo off -set check_host=IP -set check_hostname=TEST -set filename=.\log\%check_hostname%.log +set check_host=%1 +set check_hostname=%2 + +set file_path=.\log +set filename=%file_path%/%check_hostname%.log + +REM set the max filesize +set maxbytesize=1024000 :loop set ldt=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2% %TIME:~0,2%:%TIME:~3,2%:%TIME:~6,2% -ping -n 1 %check_host% | find "TTL=" >nul + +for %%A in (%filename%) do set size=%%~zA +echo %size% %maxbytesize% +if %size% gtr %maxbytesize% call:rotate + +ping -w 1 -n 1 %check_host% | find "TTL=" >nul if errorlevel 1 ( echo %ldt% - ping failed %check_hostname% - %check_host% ECHO %ldt% - ping failed %check_hostname% - %check_host% >>%filename% + + ) else ( echo %ldt% - ping %check_hostname% - %check_host% ) + + @timeout /t 1 /nobreak >nul goto loop +REM rotate +:rotate + if exist %file_path%\old_logs\%check_hostname%.log.5 ( + rem file exists + ) + if exist %file_path%\old_logs\%check_hostname%.log.4 ( + rem file exists + move %file_path%\old_logs\%check_hostname%.log.4 %file_path%\old_logs\%check_hostname%.log.5 + ) + if exist %file_path%\old_logs\%check_hostname%.log.3 ( + rem file exists + move %file_path%\old_logs\%check_hostname%.log.3 %file_path%\old_logs\%check_hostname%.log.4 + ) + if exist %file_path%\old_logs\%check_hostname%.log.2 ( + rem file exists + move %file_path%\old_logs\%check_hostname%.log.2 %file_path%\old_logs\%check_hostname%.log.3 + ) + if exist %file_path%\old_logs\%check_hostname%.log.1 ( + rem file exists + move %file_path%\old_logs\%check_hostname%.log.1 %file_path%\old_logs\%check_hostname%.log.2 + ) + move %file_path%\%check_hostname%.log %file_path%\old_logs\%check_hostname%.log.1 + EXIT /B 0