fixed some logrotate issues~
parent
fc33eccb2b
commit
47b320f196
|
@ -1,59 +1,54 @@
|
||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
|
|
||||||
set check_host=%1
|
set check_host=%1
|
||||||
set check_hostname=%2
|
set check_hostname=%2
|
||||||
|
|
||||||
set file_path=.\log
|
set file_path=.\log
|
||||||
set filename=%file_path%/%check_hostname%.log
|
set filename=%file_path%/%check_hostname%.log
|
||||||
|
|
||||||
REM set the max filesize
|
REM set the max filesize (512kb)
|
||||||
set maxbytesize=1024000
|
set maxbytesize=512000
|
||||||
|
|
||||||
:loop
|
:loop
|
||||||
|
|
||||||
|
REM get date time
|
||||||
set ldt=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2% %TIME:~0,2%:%TIME:~3,2%:%TIME:~6,2%
|
set ldt=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2% %TIME:~0,2%:%TIME:~3,2%:%TIME:~6,2%
|
||||||
|
|
||||||
for %%A in (%filename%) do set size=%%~zA
|
REM check filesize, if over maxbytesize run rotate function
|
||||||
echo %size% %maxbytesize%
|
if exist %filename% (
|
||||||
if %size% gtr %maxbytesize% call:rotate
|
for %%A in (%filename%) do set size=%%~zA
|
||||||
|
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%
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
REM 1 ping with one sec timeout
|
||||||
|
ping -w 1 -n 1 %check_host% | find "TTL=" >nul
|
||||||
|
if errorlevel 1 (
|
||||||
|
REM ping failed - log into file
|
||||||
|
echo %ldt% - ping failed %check_hostname% - %check_host%
|
||||||
|
echo %ldt% - ping failed %check_hostname% - %check_host% >>%filename%
|
||||||
|
) else (
|
||||||
|
REM ping succeed
|
||||||
|
echo %ldt% - ping %check_hostname% - %check_host%
|
||||||
|
)
|
||||||
|
REM wait 1 sec for next ping
|
||||||
@timeout /t 1 /nobreak >nul
|
@timeout /t 1 /nobreak >nul
|
||||||
|
|
||||||
goto loop
|
goto loop
|
||||||
|
|
||||||
REM rotate
|
REM rotate logs
|
||||||
|
REM move logs if they exist
|
||||||
:rotate
|
:rotate
|
||||||
if exist %file_path%\old_logs\%check_hostname%.log.5 (
|
REM move file if exist
|
||||||
rem file exists
|
|
||||||
)
|
|
||||||
if exist %file_path%\old_logs\%check_hostname%.log.4 (
|
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
|
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 (
|
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
|
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 (
|
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
|
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 (
|
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%\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
|
move %file_path%\%check_hostname%.log %file_path%\old_logs\%check_hostname%.log.1
|
||||||
|
|
Loading…
Reference in New Issue