#59607 - 2001-10-05 02:17 AM
How long has system been running
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11620
Loc: CA
|
Okay since parsing is not my forte, I'm looking for some more help with the following. I need to know how long a Server or Workstation has been up and running. I can find this by shelling out and running either one of the following.NOTE: I am using KiXtart v3.63 net statistics workstation net statistics server Which comes back with results like this: net statistics workstation Workstation Statistics for \\FMLAST-D01 Statistics since 10/1/2001 4:41 PM
Now I can use @TIME to get the current time but I have an issue here. @TIME uses a 24 hour clock and net statistics uses a 12 hour clock with AM PM During a user logon I want to check and see how long the system has been running. If the system has only been up and running for less then one minute I want to take a different action then if the system has been up and running for a long time. I'm checking if a service is running. If the system is a server and has just been restarted, it is prone to a 30 seconds to maybe upwards of a couple minutes before all of the services are running. If I check for this service right away, it may not be there and I would falsely log that the service was not running, when in fact it may have only needed another 30 seconds before it was running. Using either this method (or any other method) how can I determine and place in a useable variable, that the system has been running or not running for more then 1 minute? Thanks in advance for any assistance. 
|
Top
|
|
|
|
#59608 - 2001-10-05 03:06 AM
Re: How long has system been running
|
Les
KiX Master
   
Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
|
Hey DOC, Have you had a look at the ResKit tool UPTIME? quote:
C:\Program Files\Resource Pro Kit>uptime \\999-51-566 has been up for: 0 day(s), 0 hour(s), 23 minute(s), 13 second(s)
I know, it's external, but you don't need to calculate from current time and with the output, and it's all on one line so it's easy to parse. Sample code:
code:
Break ONshell '%comspec% /c "C:\Program Files\Resource Pro Kit\uptime.exe" >C:\uptime.txt' IF Open(1,"C:\uptime.txt") = 0 $x = ReadLine(1) ? "$$X = " + $x ENDIF Close(1) ? $uptime Get $
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.
|
Top
|
|
|
|
#59610 - 2001-10-05 04:25 AM
Re: How long has system been running
|
Les
KiX Master
   
Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
|
Hi DOC, Being as I'm lazy, and I think my idea needs less code, here's what I came up with:
code:
Break ONshell '%comspec% /c "C:\Program Files\Resource Pro Kit\uptime.exe" >C:\uptime.txt' IF Open(1,"C:\uptime.txt") = 0 $x = ReadLine(1) ENDIF $ = Close(1) $day = val(substr("$x",instr("$x","day") - 4,5)) ? "$$day = " + $day $hour = val(substr("$x",instr("$x","hour") - 3,3)) ? "$$hour = " + $hour $minute = val(substr("$x",instr("$x","minute") - 3,3)) ? "$$minute = " + $minute $second = val(substr("$x",instr("$x","second") - 3,3)) ? "$$second = " + $second Get $
The reason I wrapped the substr() in val() is 'cause I'm arbitrating the length of $day to 5 chars which could conceivably exceed 3 digits. The val() will rtrim the trailing chars. You probably want interger anyway for compares. Be my guest and spit polish it. It's just a proof-of-concept. HTH
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 329 anonymous users online.
|
|
|