Solved

Batch file overflow the server memory.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Zeus black pop up screen virus 7 62
Ransomware attacks 5 83
Batch Login Script - Update default homepage 8 41
What to look for in Fraud Protection Solutions  PoC 1 33
HOW TO REMOTELY CLEAN MEROND.O WITH ESET SILENTLY PROBLEM       If you have the fortunate luck to contract the Merond.O virus on your network, it can be quite troublesome to remove as it propagates to network shares on your network. In my case, the …
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 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