none
How to build if block for srvinfo -ns | findstr "Time:" cmdlet ?

    Question

  • Hello guys,

    I`m trying to exectute a batch script only if server is restarted soon

    the host machine is windows 2000 server and WMI is not working

    so far i was able to gatther the uptime on the server with:

    srvinfo -ns | findstr "Time:"
    System Up Time: 0 Days, 7 Hr, 52 Min, 21 Sec

    How build simple batch script wich says if uptime < 2 hours contiune if uptime  > 2 hours go to end

    Thank you alot in advance !!!

    Monday, May 30, 2011 4:43 PM

Answers

  • Not exactly rocket science . . .

    @echo off
    for /F "tokens=4, 6" %%a in ('srvinfo -ns ^| find /i "Time:"') do (
      if %%a GTR 0 goto :eof
      if %%b GTR 2 goto :eof
     )

    • Marked as answer by Milen Genchev Tuesday, May 31, 2011 6:15 AM
    Monday, May 30, 2011 6:36 PM

All replies

  • Not exactly rocket science . . .

    @echo off
    for /F "tokens=4, 6" %%a in ('srvinfo -ns ^| find /i "Time:"') do (
      if %%a GTR 0 goto :eof
      if %%b GTR 2 goto :eof
     )

    • Marked as answer by Milen Genchev Tuesday, May 31, 2011 6:15 AM
    Monday, May 30, 2011 6:36 PM
  • Not exactly rocket science . . .

    @echo off
    for /F "tokens=4, 6" %%a in ('srvinfo -ns ^| find /i "Time:"') do (
      if %%a GTR 0 goto :eof
      if %%b GTR 2 goto :eof
     )


    but after 24 hours both statement for if are true

    Tuesday, May 31, 2011 7:24 AM
  • Not exactly rocket science . . .

    @echo off
    for /F "tokens=4, 6" %%a in ('srvinfo -ns ^| find /i "Time:"') do (
      if %%a GTR 0 goto :eof
      if %%b GTR 2 goto :eof
     )

    but after 24 hours both statement for if are true

    Your specification says "if uptime < 2 hours contiune if uptime  > 2 hours go to end"
    When the output from srvinfo.exe reads

    System Up Time: 1 Days, 0 Hr, 52 Min, 21 Sec

    then the system has been up for more than two hours and my batch file does exactly what you ask for. What's the problem?

    Tuesday, May 31, 2011 7:53 AM
  • it is working like a charm !

    sry the other parth of the script was giveing me wrong results

    all is fixed now, very much thank you for your time !!!

     

    Tuesday, May 31, 2011 8:25 AM