Solved

Batch file overflow the server memory.

Posted on 2013-01-26
4
399 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

The purpose of this Article is to provide information for a newly released variant of malware – with the assumption that many EE Members will have need of the information. According to “Computerworld”, well over one million web sites have been co…
Ransomware continues to be a growing problem for both personal and business users alike and Antivirus companies are still struggling to find a reliable way to protect you from this dangerous threat.
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…

761 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