Answer the question
In order to leave comments, you need to log in
How to pass the value of the find command in a .bat file to a variable?
Hello!
The essence of the program:
1. We ping to a remote host and write it to a file
2. We look for 3 words "unreachable" in this file
3. If we find 3 words, then the following commands are executed:
tasklist/v >"C:\%date%_%USERNAME%_CPU_info.txt"
systeminfo >"C:\%date%_%USERNAME%_systeminfo.txt"
netstat -abno >"C:\%date%_%USERNAME%_netstat.txt"
pathping -n 8.8.8.8 >"C:\%date%_%USERNAME%_pathping.txt"
@echo off
setlocal enabledelayedexpansion
chcp 1251 >nul
:LOOP
echo [%DATE% %TIME%] >> "C:\%date:~-10%_%USERNAME%_logfile" & ping -n 1 8.8.8..8 | find /i "TTL=">nul >> "C:\%date:~-10%_%USERNAME%_logfile.log"
FIND /C "unreachable" <"C:\%date:~-10%_%USERNAME%_logfile"
if NOT %Здесь ПЕРЕМЕННАЯ из поиска% 3 (
echo PING - ok Packet Lost = %errorlevel%
)else (
echo [%DATE% %TIME%] Destination host unreachable >> "C:\%date:~-10%_%USERNAME%_logfile_"
echo NOT OK
tasklist/v >"C:\%date%_%USERNAME%_CPU_info.txt"
systeminfo >"C:\%date%_%USERNAME%_systeminfo.txt"
netstat -abno >"C:\%date%_%USERNAME%_netstat.txt"
pathping -n 8.8.8.8>"C:\%date%_%USERNAME%_pathping.txt"
rem ping -n %pause% 127.0.0.1>nul 2>&1
)
goto LOOP
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question