show code js

2022年3月3日 星期四

cmd use ping to do something

 @echo off

@cls

@set subject=[Subject Title]

@setlocal enabledelayedexpansion

@set logfile=log_%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%%time:~9,2%.txt

@echo ================== >> %logfile%

@echo %date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%%time:~9,2% Begin %subject% >> %logfile%


for /F "delims=; tokens=1" %%i in (C:\list.txt) do (

@ping -n 1 %%i | find "最小值"

@if !ERRORLEVEL!==1 (

                @echo %%i is down >> %logfile%

) else (

                @echo %%i is life >> %logfile%

@shutdown -s -t 0 -m \\%%i

)

@echo --------- >> %logfile%

)


@echo %date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%%time:~9,2% End %subject% >> %logfile%

@echo ================== >> %logfile%


list.txt like below:

IP

IP

IP

......


沒有留言:

張貼留言