Page 1 of 1 1
Topic Options
#117771 - 2004-04-13 03:55 AM tricky uptime web page report
howyadoing Offline
Getting the hang of it

Registered: 2002-06-01
Posts: 86
Loc: Cincinnati
I used Uptime.kix from helpdesk.kixtart.org and I am trying to modify it. I would like to use the uptime command with the /d switch. There is only one extra field I want out of the up time and that is the % number. I am trying to get the server, days up, and percentage then roll it into the webpage. I have ran this script against kixstrip420 and its not out putting any errors. Am I overlooking something simple. I have tried various things and can not get any data into the html page.

Any help would be great, thanks

Code:
 ; ScriptName : Uptime.kix - Version 1.2
; Date : 04 December 2001
; Developer : Brian Petersen - http://helpdesk.kixtart.org
; Uses : Servers.txt, Uptime.ini and Uptime.exe
; Description: Generates HTML-file with graphs, based on days since Servers were booted.
; Run this Script once a day on your WebServer.

Break ON

;Modify to match your location of these files...
$ServerFile = "C:\Inetpub\Uptime\Servers.txt"
$IniFile = "C:\Inetpub\Uptime\Uptime.ini"
$HTMLfile = "C:\Inetpub\Uptime\Uptime.html"

;----- Getting Uptime stats from Servers and Writing values to the ini-file -----
; This section reads the list of servers
$nul = Open(1,"$ServerFile")
$server = ReadLine(1)
While $server <> "EndList"

If Open(2, "$ServerFile") = 0
$srvlist = 0
$read1 = ReadLine(2)
While @ERROR = 0
$read1 = ReadLine(2)
$srvlist = $srvlist + 1
Loop
EndIf
$nul = close(2)

; This section reuns the uptime command against the list of servers

$serverliste = $srvlist - 1
$counter = $counter + 1

Shell '%comspec% /c "uptime.exe /d:04/01/2004 \\$server" >C:\uptime.txt'

If Open(3,"C:\uptime.txt") = 0
$x = ReadLine(3)
$day = Val(SubStr("$x",InStr("$x","Day") + 5,3))

EndIf

If Open(3,"C:\uptime.txt") = 0
$x = ReadLine(3)
$Percent = Val(SubStr("$p",InStr("$p","Total"))

EndIf

$nul = Close(3)

;Del "C:\uptime.txt"

If Exist($IniFile)
$result = WriteProfileString($IniFile,"$server","Uptime",$day)
EndIf

If Exist($IniFile)
$result2 = WriteProfileString($IniFile2,"$server","Perctenage",$percent)
EndIf

$server = ReadLine(1)
loop
$nul = close(1)


;----- Generating HTML-file with graphs based on Uptime days -----
If RedirectOutput("$HTMLfile",1) = 0

? "<html>"
? "<head>"
? "<STYLE>"

? "BODY {"
? " font-size:10 pt;"
? " font-family: Verdana;"
? "}"

? "H3 {"
? " font-size:12 pt;"
? " font-family: Verdana;"
? "}"
? "TH {"
? " font-family : Verdana;"
? " font-size : 12;"
? "}"
? "TD {"
? " font-family : Verdana;"
? " font-size : 12;"
? "}"
? "</STYLE>"
? "</head>"
? "<body>"
? "<br>"
? "<H3>Uptime for Servers</H3>"

?"<Table border=0>"
?"<TH align=Left width=150>Server</TH><TH align=Left colspan=2>Uptime</TH><TH align=Right colspan=10 width="400">Percentage</TH>"
?"<Table border=0>"


;---LOOP---

$nul = Open(1,"$ServerFile")
$server = ReadLine(1)
While $server <> "EndList"

If Open(2, "$ServerFile") = 0
$srvlist = 0
$read1 = ReadLine(2)
While @ERROR = 0
$read1 = ReadLine(2)
$srvlist = $srvlist + 1
Loop
EndIf
$nul = close(2)

$serverliste = $srvlist - 1
$counter = $counter + 1
$ServerValue = ReadProfileString($IniFile,"$server","Uptime")
$ServerValue = ReadProfileString($IniFile2,"$server","Percentage")


? "<Table border=0>"
? "<TR>"
? "<TD width=150>$server:</TD>"
? "<TD width=100>$ServerValue days</TD>"
? "<TD width=$ServerValue bgcolor=red> </TD>"
? "</TR>"
? "</Table>"

$server = ReadLine(1)
loop
$nul = close(1)
;---LOOP---

? "<br>"
? "<br>"
? "This page was last updated " + @DATE + " - at " + @TIME

? "</body>"
? "</html>"

EndIf


Top
#117772 - 2004-04-13 04:41 AM Re: tricky uptime web page report
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You need to close a file before you can open it again or you'll need to use different file handles. See the KiXtart Manual for an explanation of OPEN/CLOSE/READLINE.
_________________________
There are two types of vessels, submarines and targets.

Top
#117773 - 2004-04-13 04:02 PM Re: tricky uptime web page report
howyadoing Offline
Getting the hang of it

Registered: 2002-06-01
Posts: 86
Loc: Cincinnati
I read through the document and kind of understand it. Is this what you mean. Thanks in advance.

Code:
 ; ScriptName : Uptime.kix - Version 1.2
; Date : 04 December 2001
; Developer : Brian Petersen - http://helpdesk.kixtart.org
; Uses : Servers.txt, Uptime.ini and Uptime.exe
; Description: Generates HTML-file with graphs, based on days since Servers were booted.
; Run this Script once a day on your WebServer.

Break ON

;Modify to match your location of these files...
$ServerFile = "C:\Inetpub\Uptime\Servers.txt"
$IniFile = "C:\Inetpub\Uptime\Uptime.ini"
$HTMLfile = "C:\Inetpub\Uptime\Uptime.html"

;----- Getting Uptime stats from Servers and Writing values to the ini-file -----
; This section reads the list of servers
$nul = Open(1,"$ServerFile")
$server = ReadLine(1)
While $server <> "EndList"

If Open(2, "$ServerFile") = 0
$srvlist = 0
$read1 = ReadLine(2)
While @ERROR = 0
$read1 = ReadLine(2)
$srvlist = $srvlist + 1
Loop
EndIf
$nul = close(2)

; This section reuns the uptime command against the list of servers

$serverliste = $srvlist - 1
$counter = $counter + 1

Shell '%comspec% /c "uptime.exe /d:04/01/2004 \\$server" >C:\uptime.txt'

If Open(3,"C:\uptime.txt") = 0
$x = ReadLine(3)
$day = Val(SubStr("$x",InStr("$x","Day") + 5,3))

EndIf

$nul = Close(3)

If Open(4,"C:\uptime.txt") = 0
$x = ReadLine(4)
$Percent = Val(SubStr("$p",InStr("$p","Total") + 5,3))

EndIf

$nul = Close(4)

;Del "C:\uptime.txt"

If Exist($IniFile)
$result = WriteProfileString($IniFile,"$server","Uptime",$day)
EndIf

If Exist($IniFile)
$result2 = WriteProfileString($IniFile2,"$server","Perctenage",$percent)
EndIf

$server = ReadLine(1)
loop
$nul = close(1)


;----- Generating HTML-file with graphs based on Uptime days -----
If RedirectOutput("$HTMLfile",1) = 0

? "<html>"
? "<head>"
? "<STYLE>"

? "BODY {"
? " font-size:10 pt;"
? " font-family: Verdana;"
? "}"

? "H3 {"
? " font-size:12 pt;"
? " font-family: Verdana;"
? "}"
? "TH {"
? " font-family : Verdana;"
? " font-size : 12;"
? "}"
? "TD {"
? " font-family : Verdana;"
? " font-size : 12;"
? "}"
? "</STYLE>"
? "</head>"
? "<body>"
? "<br>"
? "<H3>Uptime for Servers</H3>"

?"<Table border=0>"
?"<TH align=Left width=150>Server</TH><TH align=Left colspan=2>Uptime</TH><TH align=Right colspan=10 width="400">Percentage</TH>"
?"<Table border=0>"


;---LOOP---

$nul = Open(1,"$ServerFile")
$server = ReadLine(1)
While $server <> "EndList"

If Open(2, "$ServerFile") = 0
$srvlist = 0
$read1 = ReadLine(2)
While @ERROR = 0
$read1 = ReadLine(2)
$srvlist = $srvlist + 1
Loop
EndIf
$nul = close(2)

$serverliste = $srvlist - 1
$counter = $counter + 1
$ServerValue = ReadProfileString($IniFile,"$server","Uptime")
$ServerValue = ReadProfileString($IniFile,"$server","Percentage")


? "<Table border=0>"
? "<TR>"
? "<TD width=150>$server:</TD>"
? "<TD width=100>$ServerValue days</TD>"
? "<TD width=$ServerValue bgcolor=red> </TD>"
? "</TR>"
? "</Table>"

$server = ReadLine(1)
loop
$nul = close(1)
;---LOOP---

? "<br>"
? "<br>"
? "This page was last updated " + @DATE + " - at " + @TIME

? "</body>"
? "</html>"

EndIf


Top
#117774 - 2004-04-13 08:18 PM Re: tricky uptime web page report
howyadoing Offline
Getting the hang of it

Registered: 2002-06-01
Posts: 86
Loc: Cincinnati
I have changed my approach. The script runs right other than it doesnt output any data. Any suggestions.
Code:
 Break ON

;Modify to match your location of these files...
$ServerFile = "C:\Inetpub\Uptime\Servers.txt"
$IniFile = "C:\Inetpub\Uptime\Uptime.ini"
$HTMLfile = "C:\Inetpub\Uptime\Uptime.html"

;----- Getting Uptime stats from Servers and Writing values to the ini-file -----
$nul = Open(1,"$ServerFile")
$server = ReadLine(1)
While $server <> "EndList"

If Open(2, "$ServerFile") = 0
$srvlist = 0
$read1 = ReadLine(2)
While @ERROR = 0
$read1 = ReadLine(2)
$srvlist = $srvlist + 1
Loop
EndIf
$nul = close(2)

$serverliste = $srvlist - 1
$counter = $counter + 1

Shell '%comspec% /c "uptime.exe /d:04/01/2004 \\$server" >C:\uptime.txt'

If Open(3,"C:\uptime.txt") = 0
$x = ReadLine(3)
$day = Val(SubStr("$x",InStr("$x","for") + 5,3))
EndIf
$nul = Close(3)

;Del "C:\uptime.txt"

If Exist($IniFile)
$result = WriteProfileString($IniFile,"$server","Uptime",$day)
EndIf

If Open(4,"C:\uptime.txt") = 0
$p = ReadLine(4)
$per = Val(SubStr("$p",InStr("$p","total") + 5,3))
EndIf
$nul = Close(4)

;$server = ReadLine(1)

If Exist($IniFile2)
$result2 = WriteProfileString($IniFile2,"$server","Percentage",$per)
EndIf

$server = ReadLine(1)
loop
$nul = close(1)


;--
;----- Generating HTML-file with graphs based on Uptime days -----
If RedirectOutput("$HTMLfile",1) = 0

? "<html>"
? "<head>"
? "<STYLE>"

? "BODY {"
? " font-size:10 pt;"
? " font-family: Verdana;"
? "}"

? "H3 {"
? " font-size:12 pt;"
? " font-family: Verdana;"
? "}"
? "TH {"
? " font-family : Verdana;"
? " font-size : 12;"
? "}"
? "TD {"
? " font-family : Verdana;"
? " font-size : 12;"
? "}"
? "</STYLE>"
? "</head>"
? "<body>"
? "<br>"
? "<H3>Uptime for Servers</H3>"

?"<Table border=0>"
?"<TH align=Left width=150>Server</TH><TH align=Left colspan=2>Uptime</TH><TH align=Right colspan=10 width="400">Percentage</TH>"
?"<Table border=0>"


;---LOOP---

$nul = Open(1,"$ServerFile")
$server = ReadLine(1)
While $server <> "EndList"

If Open(2, "$ServerFile") = 0
$srvlist = 0
$read1 = ReadLine(2)
While @ERROR = 0
$read1 = ReadLine(2)
$srvlist = $srvlist + 1
Loop
EndIf
$nul = close(2)

$serverliste = $srvlist - 1
$counter = $counter + 1
$ServerValue = ReadProfileString($IniFile,"$server","Uptime")
$ServerValue = ReadProfileString($IniFile2,"$server","Percentage")


? "<Table border=0>"
? "<TR>"
? "<TD width=150>$server:</TD>"
? "<TD width=100>$ServerValue days</TD>"
? "<TD width=$ServerValue bgcolor=red> </TD>"
? "</TR>"
? "</Table>"

$server = ReadLine(1)
loop
$nul = close(1)
;---LOOP---

? "<br>"
? "<br>"
? "This page was last updated " + @DATE + " - at " + @TIME

? "</body>"
? "</html>"

EndIf







Top
#117775 - 2004-04-13 08:21 PM Re: tricky uptime web page report
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Put DEBUG ON into the first line of code and step through it to see what the script is doing.
_________________________
There are two types of vessels, submarines and targets.

Top
#117776 - 2004-04-13 09:49 PM Re: tricky uptime web page report
howyadoing Offline
Getting the hang of it

Registered: 2002-06-01
Posts: 86
Loc: Cincinnati
I found one problem. The script executes the uptime command then Code:
 If Open(3,"C:\uptime.txt") = 0
$x = ReadLine(3)
$day = Val(SubStr("$x",InStr("$x","uptime") + 8,3))
EndIf


opens the uptime.txt file and read the data after "uptime" and write the value to the ini file and its not writing anything excepte 0.. With the origional version of this script the uptime.txt was only one line long. Is there something I need to be doing differently for my uptime.txt file that is multiple lines long? The data I am looking for in the file is aboout 15 lines down.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1257 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.136 seconds in which 0.097 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org