Need a batch code , which execute every 5 minutes automatically.
>Hi,
>
>Need a batch code , which execute every 5 minutes automatically.
Class assignment?
:Loop
REM Put your batch file's code here.
REM ...
SLEEP 300
GOTO :Loop
Anything else is a bodge that can overtake itself.
>Need a batch code , which execute every 5 minutes automatically.
I'd use the Task Scheduler to run that task. In XP or 2003 the job
could be created with Schtasks.exe.
Another option is:
:loop
batch code here
ping -n 61 127.0.0.1>nul
goto:loop
Clay Calvert
CCal...@Zanguru.com
Replace "Z" with "L"
If for whatever reason the batch takes longer than 5 minutes to run and
if it is not monitored properly it will use all system resources after
some time and render it unusable.
>> I'd use the Task Scheduler to run that task. In XP or 2003 the job
>> could be created with Schtasks.exe.
>
>If for whatever reason the batch takes longer than 5 minutes to run and
>if it is not monitored properly it will use all system resources after
>some time and render it unusable.
If that is a concern then maybe set the "Until" section's "Duration"
for 4 minutes and then check the box: "If the task is still running,
stop it at this time."
If a recursive script truly hangs, then the task task no longer
repeats.
This does not work reliably for batch files. Batch files consist of the
commands in the file itself with the process CMD.EXE. All external
commands are additional processes which are not monitored by your method.
NET USE...
If you kill the CMD.EXE for this batch file while NET hangs a process
NET.EXE will remain untouched in memory until the system is rebooted.
You will get a new NET.EXE process every 5 minutes, ie. 12 per hour (11
after the first hour). 10 hours add up to 120 hanging NET.EXE processes.
This is one of the easiest ways to make a production server crash for no
reason.
Simple process detection for net.exe can be included in the batch to log and
abort if net.exe is still running (i.e. wait another 5 minutes). A log full
of abort entries can show duration that net.exe (or whatever) is hanging.
@echo off
pslist net.exe>nul
if errorlevel 1 goto :ready
echo ERROR: net.exe still running %date% %time% >>file.log
goto :eof
:ready
echo net.exe started @ %date% %time% >>file.log
net.exe ...
pslist formerly from http://www.sysinternals.com/
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
No doubt, there might be even more complicated ways to achieve what the
OP's asked. ;-)
It's still not usable on a production machine.
In order to make this safe you will have to check every process outside
the current CMD.EXE that might want user interaction or could crash/hang.
How do you want to find the NET.EXE that the batch file invoked? There
could be more of these processes on purpose, hence your log file's wrong
here.
It's simply not a good idea to look for common process names like
NET.EXE, CMD.EXE, etc.
Honestly! NET.EXE was just being used as an example (introduced by you). If
you really need a safety net from common process names, just make a copy of
net.exe (or whatever) to a unique name specified in the batch.
If you reboot the machine after the flag file's created, you're in a
vicious circle.
No, you just don't know how to implement a flag file.
>It's still not usable on a production machine.
I wouldn't completely discount running batch files as scheduled tasks.
I have a few scripts that have been running this way nearly every 15
minutes since 1999. Originally they were on NT4 machines, but now
those servers are running 2003. The tasks are set to kill running
processes after 12 minutes.
You do make a good point in that the scripts need to be checked
periodicallly to ensure they are closing properly. This is precisely
why I added the 'kill after 12 minutes' parameter.
Thanks,