Batch Script on 2008 server - If Ping successful then

前端 未结 3 1300
耶瑟儿~
耶瑟儿~ 2020-12-21 23:34

I am attempting to write a script that will check to see if a computer is on my LAN before running the rest of my script. It is a simple backup script using robocopy

3条回答
  •  天命终不由人
    2020-12-22 00:09

    Thanks to you both. I tried both but in the end this is what worked for me

    set machine=userbox
    ping -n 1 %machine% | find "TTL=" >nul
    IF errorlevel 1 (
    echo "Computer Not On" %date% %time% > c:\scripts\%machine%-computeroff.log
    ) ELSE (
    robocopy source destination
    shutdown.exe /s /m \\%machine% /c "Mandatory Shutdown in progress. You have 10 minutes" /t 600
    echo "shutdown command given" %date% %time% > c:\scripts\shutdown-%machine%.log 
    

    Cheers

提交回复
热议问题