Solved

Batch file overflow the server memory.

Posted on 2013-01-26
4
398 Views
Last Modified: 2013-11-22
Dear Experts,

Bellow batch file shutdown remote laptops,
First it pings computer listed under computer.txt, and checks if computer is dead or alive.
if computer reachable, it will shutdown the computer in 0 second. And will print it into shutdown.txt file

(((((
for /f %%i in (C:\script\computers.txt) do call :Sub %%i
goto :eof

:Sub
echo Testing %1
set state=alive
ping -n | find /i "bytes=" || set state=dead
echo %1 is %state% >> C:\script\shutdown.txt
if %state% == alive (
    shutdown /m \\%1 /s /t 0
)
echo %state%
)))))


It was running perfectly and was shutting down remote PCs.  After changing our antivirus to Webroot Antivirus, the script cause issue to the server.  Under taskbar/Process, it creates a queue of (ping and cmd) one after another and I cause the virtual server memory to crash.

So is it my Script that cause the problem or the Antivirus cause issue?

Thanks
0
Comment
Question by:uknet80
  • 2
  • 2
4 Comments
 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 500 total points
ID: 38823759
The AV. You can't change the successive calls to ping and cmd, but I assume the AV introduces delays and does not allow for freeing memory (fast enough).

Those ((((((  and )))))  aren't in your batch file? If they are, remove them, they are superfluous and introduce additional levels of cmd.exe.
Further your ping is incomplete. It needs to be
  ping -n 1 %1 | find /i "bytes=" >nul || set state=dead
0
 

Author Comment

by:uknet80
ID: 38823928
- (((( )))) isn't part of the script
- sorry for the mistyping, it is
  ping -n 1 %1 | find /i "bytes=" >nul || set state=dead

can you please explain a bit more, what you mean by
(
The AV. You can't change the successive calls to ping and cmd, but I assume the AV introduces delays and does not allow for freeing memory (fast enough).
)

thanks
0
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 38824008
AV software needs to keep track of exe files already scanned. Else it would try to scan the ping command each time you call it, slowing down the system to an unusable state. For that, and behaviour observation, it needs to keep some more memory for itself, delay the unload of memory and code, and similar stuff.

Of course you will see ping processes created en masse, as the batch is calling ping for each PC to check. Each one is a short-living process.
The same applies to everything you put between parens, as that (usually) creates a subshell (cmd.exe process). The CALL command also might spawn a new cmd.exe.

You might get a small improvement by changing
if %state% == alive (
    shutdown /m \\%1 /s /t 0
)

Open in new window

to
if %state% == alive shutdown /m \\%1 /s /t 0

Open in new window

as this eliminates the needs for a subshell.
If you can spare the protocol file in its current "verbosity", consider using SysInternals PsShutdown instead of your batch. PsShutdown allows for a list of PCs to shut down. Together with the -n switch to set up a short connection timeout it should perform much better.
0
 

Author Closing Comment

by:uknet80
ID: 38842975
I just remove ping and used psshutdown, that does the job perfectly

thanks
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PREFACE The purpose of this guide is to explain what the SEPC Status Utility is and how it works. I have written the utility using AutoIt and have included the source code for your review. You are welcome to modify the code to your liking, but I wi…
PREFACE The purpose of this guide is to provide information to successfully install the MS SQL client tools for the Symantec Endpoint Protection Manager (SEPM) to function properly when installed on Windows 2008. AUDIENCE Information Technology…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question