PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Disciple on 12 June, 2004, 04:24:14

Title: PC Uptime
Post by: Disciple on 12 June, 2004, 04:24:14
Hey I was wondering if it was possible to make a script that will report the PC's actual uptime. It would need to be triggered by a user in the hub via "!uptime" or something similair. If someone could have a go would be great. Thanks.
Title:
Post by: Disciple on 12 June, 2004, 04:47:35
No, the uptime OF THE ACTUAL PC THE HUB IS BEING RUN ON. Like in Invision mIRC how it tells O/S and Uptime. That kinda thing...
Title:
Post by: Disciple on 12 June, 2004, 06:35:32
Nah man :( Like the uptime of the PC. When i used to run my hub on Linux, it had an Uptime script which would echo Hub Uptime followed by PC Uptime like...

Hub's Uptime: 1 day 2 hours
PC's Uptime: 4 days 3 hours

etc...

That's the kinda thing i'm after... :S
Title:
Post by: Psycho_Chihuahua on 12 June, 2004, 08:55:51
QuoteAs for the the pc's uptime. I haven't a clue. Tho Windows networking does keep track of that, I've no idea how to retrieve that info for a scriptds usage.

Well a friend of mine wrote a little Tool he uses on his Server to show a couple of statistics on his Intranet. Just that it has nothing to do with Ptokax.

As long as the Tool is running you can use these variables in a htm page on the same computer:

for Internet Status -> @online@
for System Total Online -> @totaltage@
for Windows Total Online since first start of Tool -> @akttage@
Computer in same Network -> @netzwerk@

whereas the Variables show up as the Info aqquired

perhaps someone could adapt that program ServCheck-v1-4 (http://bouncernet.ch/downloads/ServCheck-v1-4.rar)  so that it would work with the Hub as well. If i am lucky i could probably get the source files (if high interest)
Title:
Post by: ??????Hawk?????? on 12 June, 2004, 11:41:42
Heya Peeps :-)

Maby Someone with a better knowledge of lua than me can convert this VB script.

V.B SCRIPT
'Uptime script 0.000003 by Gadget
Dim Uptime,sBotName,sRegPath,sStart,sStop,iUptime,iDowntime,iBoots,iCrashes,iResets,iPackets,sLogStart,sSaved

Sub Main()
 sBotName="Uptime"
 sRegPath="HKEY_LOCAL_MACHINE\SOFTWARE\NeoModus\Hub\Stats\"
 Set Uptime=New clsUptime
 tmrScriptTimer.Interval = 60000
 tmrScriptTimer.Enabled = True
End Sub

Sub tmrScriptTimer_Timer()
 iUptime=iUptime+DateDiff("s",sSaved,Now)
 WriteReg
End Sub

Sub DataArival(curUser,sCurData)
 If Left(sCurData,1)="<" Then
   If Right(LCase(sCurData),8)="> uptime" And curUser.bOperator Then
     iTotalUptime=iUptime+DateDiff("s",sSaved,Now)
     sMsg="Hub uptime and statistics since "+sLogStart
     sMsg=sMsg+vbCrLf+"Last hub boot"+vbTab+sStart
     sMsg=sMsg+vbCrLf+"Current uptime "+vbTab+FmtSeconds(DateDiff("s",sStart,Now))
     sMsg=sMsg+vbCrLf+"Total uptime "+vbTab+FmtSeconds(iTotalUptime)
     sMsg=sMsg+vbCrLf+"Total downtime "+vbTab+FmtSeconds(iDowntime)
     sMsg=sMsg+vbCrLf+"Reliability "+vbTab+vbTab+CStr(CCur(iTotalUptime/(iTotalUptime+iDowntime)*100))+" %"
     sMsg=sMsg+vbCrLf+"Boots "+vbTab+vbTab+cStr(iBoots)
     sMsg=sMsg+vbCrLf+"Crashes "+vbTab+vbTab+cStr(iCrashes)
     sMsg=sMsg+vbCrLf+"Resets "+vbTab+vbTab+cStr(iResets)
     sMsg=sMsg+vbCrLf+"Packets "+vbTab+vbTab+cStr(iPackets)+" ("+CStr(CCur(iPackets/(iTotalUptime/60)))+" per minute)"
     curUser.PrivateMessage CStr(sBotName),CStr(sMsg)
   End If
 End If
 iPackets=iPackets+1
End Sub

Class clsUptime
 Sub Class_Initialize
   ReadReg
   If sLogStart="" Then
     sStart=CStr(Now):sStop="-":iUptime=0:iDowntime=0:iBoots=0:iCrashes=0:iResets=0:iPackets=0:sLogStart=CStr(Now)
     WriteReg
     Exit Sub
   End If
   If sStop="-" Then
     iCrashes=iCrashes+1
     sStart=CStr(Now)
   ElseIf DateDiff("s",sStop,Now)<5 Then
     iResets=iResets+1
   Else
     iBoots=iBoots+1
     iDowntime=iDowntime+DateDiff("s",sStop,Now)
     sStart=CStr(Now)
   End If
   sStop="-"
   WriteReg
 End Sub
 Sub Class_Terminate
   iUptime=iUptime+DateDiff("s",sSaved,Now)
   sStop=CStr(Now)
   WriteReg
 End Sub
End Class

Sub ReadReg
 On Error Resume Next
 Set wshShell = CreateObject("WScript.Shell")
 sStart   =wshShell.RegRead(sRegPath+"Start")
 sStop    =wshShell.RegRead(sRegPath+"Stop")
 iUptime  =CDbl(wshShell.RegRead(sRegPath+"Uptime"))
 iDowntime=CDbl(wshShell.RegRead(sRegPath+"Downtime"))
 iBoots   =CDbl(wshShell.RegRead(sRegPath+"Boots"))
 iCrashes =CDbl(wshShell.RegRead(sRegPath+"Crashes"))
 iResets  =CDbl(wshShell.RegRead(sRegPath+"Resets"))
 iPackets =CDbl(wshShell.RegRead(sRegPath+"Packets"))
 sLogStart=wshShell.RegRead(sRegPath+"LogStart")
End Sub

Sub WriteReg
 On Error Resume Next
 Set wshShell = CreateObject("WScript.Shell")
 wshShell.RegWrite sRegPath+"Start",sStart,"REG_SZ"
 wshShell.RegWrite sRegPath+"Stop",sStop,"REG_SZ"
 wshShell.RegWrite sRegPath+"Uptime",CStr(iUptime),"REG_SZ"
 wshShell.RegWrite sRegPath+"Downtime",CStr(iDowntime),"REG_SZ"
 wshShell.RegWrite sRegPath+"Boots",CStr(iBoots),"REG_SZ"
 wshShell.RegWrite sRegPath+"Crashes",CStr(iCrashes),"REG_SZ"
 wshShell.RegWrite sRegPath+"Resets",CStr(iResets),"REG_SZ"
 wshShell.RegWrite sRegPath+"Packets",CStr(iPackets),"REG_SZ"
 wshShell.RegWrite sRegPath+"LogStart",sLogStart,"REG_SZ"
 sSaved=CStr(Now)
End Sub

Function FmtSeconds(iSeconds)
 iSec=iSeconds
 iYears=Int(iSec/60/60/24/365):iSec=iSec-iYears*60*60*24*365
 iMonths=Int(iSec/60/60/24/30):iSec=iSec-iMonths*60*60*24*30
 iDays=Int(iSec/60/60/24):iSec=iSec-iDays*60*60*24
 iHours=Int(iSec/60/60):iSec=iSec-iHours*60*60
 iMinutes=Int(iSec/60):iSec=iSec-iMinutes*60
 If iYears>0 Then FmtSeconds=CStr(iYears)+" years, "
 If iMonths>0 Then FmtSeconds=FmtSeconds+CStr(iMonths)+" months, "
 If iDays>0 Then FmtSeconds=FmtSeconds+CStr(iDays)+" days, "
 If iHours>0 Then FmtSeconds=FmtSeconds+CStr(iHours)+" hours, "
 If iMinutes>0 Then FmtSeconds=FmtSeconds+CStr(iMinutes)+" minutes, "
 FmtSeconds=FmtSeconds+CStr(iSec)+" seconds"
End Function
Title:
Post by: NotRabidWombat on 12 June, 2004, 17:05:24
http://www.microsoft.com/ntserver/nts/downloads/management/uptime/default.asp

Just make a script to have it output to a file and then read the file.

-NotRabidWombat
Title:
Post by: Disciple on 12 June, 2004, 17:20:39
Hmmm... good idea... But seeing I have no idea about scripting, I wouldn't know where to start. Does anyone wanna have a go at making this?
Title:
Post by: plop on 13 June, 2004, 03:15:11
like this for example (execute with the lua command line).
        execute("uptime > uptime.lst")
         local serverup = ""
         if readfrom("uptime.lst") then
            readfrom("uptime.lst")
            serverup = read()
            writeto()
            remove("uptime.lst")
         end
         print(serverup)

plop
Title:
Post by: Sudds on 13 June, 2004, 11:46:38
Id like to try this script and use it in my hub.
But the link to the microsoft tool is dead and i cannot seem to find it on the web site.
Can u put it on a web or find a different site with it so i can try your script?
Cheers

Sudds
Title:
Post by: Sudds on 13 June, 2004, 11:52:53
Sorry after looking around a while i found it at
http://www.microsoft.com/downloads/details.aspx?FamilyID=bc18ffdb-d6fe-400b-b892-94783ae44c91&displaylang=en

i think it is the right tool. Is it?

Sudds
Title:
Post by: [PT]CableGuy on 13 June, 2004, 15:27:47
QuoteOriginally posted by Sudds
...i think it is the right tool. Is it?
Well..."that one" is for NT4  and Win2000 . :]

For WinXP  (Professional only) , there is a "microsoft tool" called systeminfo  !!!

Just open an "MS-Dos Command Prompt" (Start-->Run-->cmd)
...and type systeminfo /? , for all available options. ;)
For more info on "this tool" , please visit ---> MS-Systeminfo (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/systeminfo.mspx)
Title:
Post by: NotRabidWombat on 13 June, 2004, 16:55:06
uptime will work for XP as well

I did not note systeminfo because there are fewer formatting options and you must grep the information (I think it's find in DOS) out of the list.

-NotRabidWombat
Title:
Post by: [PT]CableGuy on 13 June, 2004, 19:39:06
QuoteOriginally posted by NotRabidWombat
uptime will work for XP as well...
:D  You're right !!! my fault... :rolleyes:
This is because i have a WinXP Home edition and both applications doesnt work on it...LOL.
Sorry , if i've "mistaken" someone ;)
Title:
Post by: Event_Horizon on 13 June, 2004, 21:18:21
if it's possible to readout the uptime from an other application u can use AIDA32 3.90 ( latest release ) it's a real good tool
Title:
Post by: Disciple on 14 June, 2004, 05:48:32
Wow! Thanks a lot Mutor. One mroe thing tho hehe... is there any way you can make just the Current System Uptime:  line display, and make it display to the hub chat instead of private msg?
Title:
Post by: Event_Horizon on 14 June, 2004, 09:05:39
THX Mutor didn't know that :)
Title:
Post by: Disciple on 14 June, 2004, 14:54:28
Excellent. Thanks a heap man! :)