Skip to main content

how to use sleep or wait in a simple command execution

well, the obvious is to use “sleep.exe”. what if you don’t have it available? this is something i ran into today when i was on a server, needed to loop through a log and keep searching for a value… and didn’t want to sit around waiting.

simply, this was the command i was trying to get to run:

for /l %a in (1,1,5000) do find /i “failure” myLog.log & sleep 10

this didn’t work because sleep.exe wasn’t there. so, i did what any good internet citizen would do: google. i came up with this link: http://malektips.com/dos0017.html.

it gives a couple of examples using choice and ping. since choice was available, i decided to try this. my constructed command became:

for /l %a in (1,1,5000) do choice /t 10 /d y >nul & find /i “failure” myLog.log

now i get a 10 second delay between each loop. :)

Comments

  1. Hey Marcus, this is Troy...Good Tip!!

    I found that there is a two (2) percent-symbols '%%a' instead of one. Also, I understand how a For...In...Do works in a batch-file, however, what is the reason for the three elements and the values you chose, inside the parethesis (e.g. 1,1,5000)?

    Thanks

    ReplyDelete
  2. Troy again...

    It just dawned on me why your example only has one percent-symbol (e.g. %a), as opposed to having two (e.g. %%a). When running directly on the command-line, you only need one percent-symbol. When running within a batch-file, you need two.

    Details, details...

    ReplyDelete
  3. hey troy! it was good seeing you at smug and nice hearing from you.

    yes, you're absolutely right. %% is required when for loops are handled inside of a batch file. i was simply running that from the cmd shell, searching for a certain condition to pop up.

    regarding the other question about (1,1,5000), when you use FOR /L you're specifying to step through a sequence of numbers. what's inside the parentheses breaks down to the following:

    1 - first # in sequence
    1 - indicates the # of steps
    5000 - last # in sequence

    so i'm telling it, do this starting from 1 until i get to 5000, and go 1 number at a time. switching the second value to 5, for example would step 5 numbers at a time.

    hope that helps...

    ReplyDelete
  4. Thanks for the explanation, Marcus!! I never knew you could do that...

    ReplyDelete
  5. for very long i was trin the cmd scripts....wel to make users in server no problum but to run some condition and the bigest help is the ping sweep....thanks a lot dude..u have been a big help...keep up the good work...:)

    ReplyDelete

Post a Comment

Popular posts from this blog

using preloadpkgonsite.exe to stage compressed copies to child site distribution points

UPDATE: john marcum sent me a kind email to let me know about a problem he ran into with preloadpkgonsite.exe in the new SCCM Toolkit V2 where under certain conditions, packages will not uncompress.  if you are using the v2 toolkit, PLEASE read this blog post before proceeding.   here’s a scenario that came up on the mssms@lists.myitforum.com mailing list. when confronted with a situation of large packages and wan links, it’s generally best to get the data to the other location without going over the wire. in this case, 75gb. :/ the “how” you get the files there is really not the most important thing to worry about. once they’re there and moved to the appropriate location, preloadpkgonsite.exe is required to install the compressed source files. once done, a status message goes back to the parent server which should stop the upstream server from copying the package source files over the wan to the child site. anyway, if it’s a relatively small amount of packages, you can

How to Identify Applications Using Your Domain Controller

Problem Everyone has been through it. We've all had to retire or replace a domain controller at some point in our checkered collective experiences. While AD provides very intelligent high availability, some applications are just plain dumb. They do not observe site awareness or participate in locating a domain controller. All they want is the name or IP of one domain controller which gets hardcoded in a configuration file somewhere, deeply embedded in some file folder or setting that you are never going to find. How do you look at a DC and decide which applications might be doing it? Packet trace? Logs? Shut it down and wait for screaming? It seems very tedious and nearly impossible. Potential Solution Obviously I wouldn't even bother posting this if I hadn't run across something interesting. :) I ran across something in draftcalled Domain Controller Isolation. Since it's in draft, I don't know that it's published yet. HOWEVER, the concept is based off

sccm: content hash fails to match

back in 2008, I wrote up a little thing about how distribution manager fails to send a package to a distribution point . even though a lot of what I wrote that for was the failure of packages to get delivered to child sites, the result was pretty much the same. when the client tries to run the advertisement with an old package, the result was a failure because of content mismatch. I went through an ordeal recently capturing these exact kinds of failures and corrected quite a number of problems with these packages. the resulting blog post is my effort to capture how these problems were resolved. if nothing else, it's a basic checklist of things you can use.   DETECTION status messages take a look at your status messages. this has to be the easiest way to determine where these problems exist. unfortunately, it requires that a client is already experiencing problems. there are client logs you can examine as well such as cas, but I wasn't even sure I was going to have enough m