NTDOCAdministrator
(KiX Master)
2001-10-05 02:17 AM
How long has system been running

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.

Les
(KiX Master)
2001-10-05 03:06 AM
Re: How long has system been running

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 ON

shell '%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 $




NTDOCAdministrator
(KiX Master)
2001-10-05 03:37 AM
Re: How long has system been running

Hi Les,

Thanks for the quick reply. Yes, I know of the utility and I could use that, but I'm still back to part of my original problem.

Parsing out the vital information from the line and comparing and then taking action.

I guess I could find the minutes portion and then grab out the three characters from the left and then strip out blanks which should leave me with either 1 or 2 numbers. Then I could do IF > 1 do task or IF < 1 do other task?

Does this sound right? or is there maybe a better way? I'll start trying to strip out the wanted portion and see where I get.

I guess I need to learn parsing and do while stuff a little better, it keeps coming up over and over lately.

Les
(KiX Master)
2001-10-05 04:25 AM
Re: How long has system been running

Hi DOC,
Being as I'm lazy, and I think my idea needs less code, here's what I came up with:
code:

Break ON

shell '%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

NTDOCAdministrator
(KiX Master)
2001-10-05 04:56 AM
Re: How long has system been running

Wow! Les,

I think your going to have to change your signature again. Maybe to PARSING GUY or something.

I'm banging my head and you fix it on the fly. It works great on at least one of my test systems.

I see what your doing, why the Hell can't I think of these things when I want them. Maybe I need to change to a different JOLT Cola or something.

Thanks again Les great job. If I run into any problems on any other systems I'll let you know, but so far so good.

Les
(KiX Master)
2001-10-05 06:31 AM
Re: How long has system been running

Eh DOC,
Don't be too hard on yourself. It's probably that love fog you're in. This string stuff doesn't exactly roll off my fingers either.

You had it at your finger tips. To quote you, "I guess I could find the minutes portion and then grab out the three characters from the left and then strip out blanks..."

I'm still learning from the master Bryce (I genuflect to him). Check out his sample.
http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=001952