Solved

Batch file overflow the server memory.

Posted on 2013-01-26
4
388 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 68

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 68

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

For those of you actively in the Malware fightling business, we now have available an amazing new tool in the malware wars (first recommended to me by rpggamergirl (http://www.experts-exchange.com/M_3598771.html), the Zone Advisor for the Virus and …
By the time you finish reading this article, you may have already lost all your money because you don't know the simple steps to securing your BitCoin wallet. BitCoin is an incredible invention. It is a decentralized currency system, which is the…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now