Announcement

Collapse
No announcement yet.

wait or pause with .bat scripts

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • wait or pause with .bat scripts

    Does anyone know how to make batch files wait after they have processes information...for example, it would wait to process all the information, and then write to a text file. The problem I am running into is that it once it gets part of the data it writes to a text file too quick and doesn't get all the data.

  • #2
    Re: wait or pause with .bat scripts

    I believe I found the solution, I think its the sleep command. So if you wanted to script to wait 2 minutes before the next command it would be:

    sleep 120

    I will test this out.

    Comment


    • #3
      Re: wait or pause with .bat scripts

      Nope it didn't like that...

      Comment


      • #4
        Re: wait or pause with .bat scripts

        why don't you like it?
        Marcel
        Technical Consultant
        Netherlands
        http://www.phetios.com
        http://blog.nessus.nl

        MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
        "No matter how secure, there is always the human factor."

        "Enjoy life today, tomorrow may never come."
        "If you're going through hell, keep going. ~Winston Churchill"

        Comment


        • #5
          Re: wait or pause with .bat scripts

          http://labmice.techtarget.com/articles/batchcmds.htm
          PAUSE

          Suspends processing of a batch program and displays a message prompting the user to press any key to continue.

          Prompting the user to continue the program
          Windows 2000 displays the following message in response to the pause command:

          Press any key to continue . . .
          Will that do what you want?

          Tom
          Tom Jones
          MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
          PhD, MSc, FIAP, MIITT
          IT Trainer / Consultant
          Ossian Ltd
          Scotland

          ** Remember to give credit where credit is due and leave reputation points where appropriate **

          Comment


          • #6
            Re: wait or pause with .bat scripts

            I had a similar issue when I had a logon script in a domain, plus many startup programs, that all fired at logon. The computers where getting bogged down, so I added this...

            PING 1.1.1.1 -n 1 -w 30000 >NUL

            believe it or not this works and as far as i can tell is the only way too! Change the 30000 for longer or shorter 'pauses'.
            "...if I turn out to be particularly clear, you've probably misunderstood what I've said” - Alan Greenspan

            Comment


            • #7
              Re: wait or pause with .bat scripts

              The pause isn't going to do it I think...heres my script:

              @ECHO OFF
              TITLE Website Check

              REM -----------------------------------
              REM

              SET MachineList=MachineList.txt
              SET ResultsFile=Results.txt

              REM
              REM -----------------------------------

              CLS
              ECHO.
              IF NOT EXIST "%MachineList%" (
              ECHO Cannot locate Machine List: %MachineList%
              PAUSE>NUL
              GOTO :EOF
              )

              ECHO Processing all machine names in %MachineList% . . .
              ECHO.

              FOR /f "tokens=*" %%M in (%MachineList%) do CALL :CHECK "%%M"

              GOTO :EOF

              :CHECK
              SET Machine=%~1
              SET Machine=%Machine: =%

              PING -n 1 -w 1000 %Machine%>NUL
              IF %ERRORLEVEL% NEQ 0 ECHO %Machine% did not respond at %Time%>>%ResultsFile%

              sleep 120

              cscript SENDMAIL.vbs

              :EOF

              So I run into the problem when sending the file. It doesn't wait for all the pings to go through. I have "PING -n 1 -w 1000 %Machine%>NUL" in there so that rules that out. Not really sure how to do this...

              Comment


              • #8
                Re: wait or pause with .bat scripts

                you actually have to keep the 1.1.1.1 ip address in there as that will always be an invalid IP. The 30000 is the delay in waiting for a response.
                "...if I turn out to be particularly clear, you've probably misunderstood what I've said” - Alan Greenspan

                Comment


                • #9
                  Re: wait or pause with .bat scripts

                  I'm not pinging 1.1.1.1 though, I have a list of websites that it pings from...putting that there will just make them all not respond.

                  Comment


                  • #10
                    Re: wait or pause with .bat scripts

                    If I take out the "sleep 120 cscript SENDMAIL.vbs" everything runs fine, it writes to the text file all the websites that didn't respond. I actually had to download the toolpack for server 2003 to use the "sleep" command.

                    Comment


                    • #11
                      Re: wait or pause with .bat scripts

                      whoa, it is ironic that the script you are trying to write is a pinging machine script. The line i posted i just to generate a pause in any script, with the intentional invalid IP.
                      "...if I turn out to be particularly clear, you've probably misunderstood what I've said” - Alan Greenspan

                      Comment


                      • #12
                        Re: wait or pause with .bat scripts

                        Yeah, I might give up on it soon and just settle with sending it manually.

                        Comment


                        • #13
                          Re: wait or pause with .bat scripts

                          Well if you giving up anyway................there are many such utilities that do pretty much what you are trying to do, not from the command line. I have been looking for a open source version of a server monitoring package, with little success. You have inspired me to resume my search
                          "...if I turn out to be particularly clear, you've probably misunderstood what I've said” - Alan Greenspan

                          Comment


                          • #14
                            Re: wait or pause with .bat scripts

                            Ok, if you find anything good let me know. Thanks.

                            Comment


                            • #15
                              Re: wait or pause with .bat scripts

                              Ok I refuse to give up! Heres a vbs script that I'm trying it with...I get an error when it starts to write the text file though, If I can get that to write properly then this will be golden.

                              Set fso = CreateObject("Scripting.FileSystemObject")
                              set tf = fso.CreateTextFile("c:\PingResults.txt", True)
                              Set objMessage = CreateObject("CDO.Message")
                              i = 1

                              strMachines = "www.google.com;www.yahoo.com"
                              aMachines = split(strMachines, ";")

                              For Each machine in aMachines
                              Set objPing = GetObject("winmgmts:{impersonationLevel=impersonat e}")._
                              ExecQuery("select * from Win32_PingStatus where address = '"_
                              & machine & "'")
                              For Each objStatus in objPing
                              If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
                              tf.writeline "Computer " & machine & " is not reachable"
                              i = i + 1
                              else
                              end if
                              Next
                              tf.close
                              Next

                              Comment

                              Working...
                              X