On the weblogic server there are 2 nodes, sometimes the memory on the server ends and you have to reboot the nodes, wrote bat.file that checks the status of the nodes and if the memory exceeds the allowable rate, it reboots the node

@Echo Off SET procName=notepad++.exe SET RAMLimit=20 Set "sum=0" For /F "Tokens=6-7 Delims=., " %%a In ( 'TaskList /NH /FI "ImageName Eq %procName%"') Do Set/A sum+=%%a%%b echo %sum% echo %procName% echo %RAMLimit% if %RAMLimit% GEQ %sum% taskkill /im notepad++.exe* /f >7.txt Pause 

This script works for the experiment. I took the notepad, but when it completes the task of the notepad, it finishes itself and I need this bat to work all the time.

  • 2
    I need this baht to work all the time. BAT / CMD are not designed for continuous operation. That is, you can loop them, but you definitely need one hundred percent processor load? Do the same, but let's say on VBS. Or run once a minute through the scheduler. \ - Akina

1 answer 1

Add a label, for example :BEGIN and make the transition to it from the end of the .bat file

 @Echo Off :BEGIN SET procName=notepad++.exe SET RAMLimit=20 Set "sum=0" For /F "Tokens=6-7 Delims=., " %%a In ( 'TaskList /NH /FI "ImageName Eq %procName%"') Do Set/A sum+=%%a%%b echo %sum% echo %procName% echo %RAMLimit% if %RAMLimit% GEQ %sum% taskkill /im notepad++.exe* /f >7.txt TIMEOUT /T 600 GOTO BEGIN 

UPD In order not to heavily load the processor, set the delay to 600 seconds = 10 minutes.

TIMEOUT command works in WINDOWS versions starting with VISTA