Page 1 of 1 1
Topic Options
#68865 - 2002-08-06 06:49 PM Help with enhancements to Bryces wanreport script
ANOA Offline
Fresh Scripter

Registered: 2002-06-12
Posts: 19
Loc: UK
I came across this excellent piece of code that was posted by Bryce. I would like to do the following but I am having little success:

1. On the first run store the responses to an ini file.
2. After 5 minutes read and display the historic data stored in (1) above.
3. Overwrite (1) above with the current responses.
4. Repeat.

The trouble I am having is in the timing logic. Any help here would be greatly appreciated.

code:
 
break on cls
;--------------------------------------------------------------------------------------------------------
;WanReport.kix
;
; This script will ping a list of ip#'s displaying the status of each connection.
;
; Create a comma delimited file in the following format.
; <Common name>,<ipadress>
; <Common name>,<ipadress>
; <Common name>,<ipadress>
; ...
;
; Example: (the numbers have been changed to protect the innocent, please use FULL IP#'s)
; Arlington Super Store,10.9.x.x
; Arrowhead Crossing,10.9.x.x
; Auburn Hills,10.9.191.x.x
; Baybrook Super Store,10.9.x.x
;--------------------------------------------------------------------------------------------------------
$file = "wanrouters.csv" ;CSV database of ip#'s to scan
$sleep_Min = 1 ;Number of minutes between scans
$timeOut = "3000" ;The max ping timeout
$fast = 95 ;Ping time is MS, used for color codes
$slow = 350 ;Ping time is MS, used for color codes

$temp = "%temp%\temp.dat"
;--------------------------------------------------------------------------------------------------------
$sleep_min = $sleep_Min*60

:top
$line = 1
$col2 = 10
$col3 = 45

If exist($file) = 1
copy "$file" "%temp%\wanrouters.csv"
else
? "Could not find $file. Script ending"
exit
endif

$nul = open(1,"%temp%\$file",2)
$data = readline(1)

at($line,0) 'Press ' color y+/n '"CTRL-C"' color w/n ' to Exit, AUTO repeat set to $sleep_Min seconds' $line = $line + 1

do
$Store = substr("$data",1,instr("$data",",")-1)
$Store_Router = substr("$data",instr("$data",",")+1,len("$data"))

Shell'%comspec% /c ping -n 1 -w $timeout $Store_Router | find "Reply" > "$temp"'
$q = open(2,"$temp",2) $reply = readline(2) $q = close(2)
if $reply <> ""
$reply_time = substr("$reply",instr("$reply","time")+4,instr("$reply","TTL=")-instr("$reply","time")-5)
at($line+1,0)" "
at($line,0)color g/n "OK" color w/n
select
case val(substr("$reply_time",2,instr("$reply_time","ms"))) <= $fast
color g+/n
case val(substr("$reply_time",2,instr("$reply_time","ms"))) <= $slow
color y+/n
case val(substr("$reply_time",2,instr("$reply_time","ms"))) > $slow
color r+/n
endselect
select
case substr("$reply_Time",1,1) = "="
" " substr("$reply_Time",2,len("$reply_Time")-1) color w/n
case substr("$reply_Time",1,1) = "<"
" $reply_Time" color w/n
endselect
at($line,$col2)"$store" At($line,$col3)"$Store_Router" $line = $line + 1
else
at($line+1,0)" "
at($line,0)color r+/n "TIMEOUT!" color w/n at($line,$col2)"$store" at($line,$col3)"$Store_Router" $line = $line + 1
endif
$data = readline(1)
until @error <> 0
$nul = close(1)
del "$temp"
? "Sleeping for " $sleep_min "sec"
Sleep $sleep_Min
goto top
exit





Top
#68866 - 2002-08-06 07:15 PM Re: Help with enhancements to Bryces wanreport script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
What is the problem with the timing logic? There is no logic at all, the script just sleeps for 1 minute (60 seconds) and then goes back to the beginning.
_________________________
There are two types of vessels, submarines and targets.

Top
#68867 - 2002-08-06 07:24 PM Re: Help with enhancements to Bryces wanreport script
ANOA Offline
Fresh Scripter

Registered: 2002-06-12
Posts: 19
Loc: UK
I am not having a problem with the sleep logic. My problem is with a timing logic to write the results to a file on first run and then read those results in five minutes later to display an extra column as historic data !
Top
#68868 - 2002-08-06 07:31 PM Re: Help with enhancements to Bryces wanreport script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
What does have this to do with timing?

On the first run, use WRITEPROFILESTRING to write to the mot yet existing file. On every subsequent run, read from the already existing file with READPROFILESTRING.
code:
Pseudocode
:top
if exist($file)
readprofilestring()
;display the old stuff
endif

; do stuff

;write new stuff
writeprofilestring()
; wait 60 seconds
sleep 60
goto top

_________________________
There are two types of vessels, submarines and targets.

Top
#68869 - 2002-08-06 07:40 PM Re: Help with enhancements to Bryces wanreport script
ANOA Offline
Fresh Scripter

Registered: 2002-06-12
Posts: 19
Loc: UK
This a misunderstanding somewhere. Here's what I originally posted:

quote:

1. On the first run store the responses to an ini file.
2. After 5 minutes read and display the historic data stored in (1) above.
3. Overwrite (1) above with the current responses.
4. Repeat.



Top
#68870 - 2002-08-06 07:56 PM Re: Help with enhancements to Bryces wanreport script
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
you want to show a history report... right?
Top
#68871 - 2002-08-06 08:01 PM Re: Help with enhancements to Bryces wanreport script
ANOA Offline
Fresh Scripter

Registered: 2002-06-12
Posts: 19
Loc: UK
Yes I want a history report based on different timing parameters from the sleep period. I still want responses every say 60 seconds but it would be great if I had a 5 minutes ago column, 10 minutes ago column etc.

I have tried the following but I am missing something.

code:
 
break on cls
;--------------------------------------------------------------------------------------------------------
;WanReport.kix
;
; This script will ping a list of ip#'s displaying the status of each connection.
;
; Create a comma delimited file in the following format.
; <Common name>,<ipadress>
; <Common name>,<ipadress>
; <Common name>,<ipadress>
; ...
;
; Example: (the numbers have been changed to protect the innocent, please use FULL IP#'s)
; Arlington Super Store,10.9.x.x
; Arrowhead Crossing,10.9.x.x
; Auburn Hills,10.9.191.x.x
; Baybrook Super Store,10.9.x.x
;--------------------------------------------------------------------------------------------------------
$file = "wanrouters.csv" ;CSV database of ip#'s to scan
$sleep_Min = 5 ;Number of seconds between scans
$timeOut = "3000" ;The max ping timeout
$fast = 95 ;Ping time is MS, used for color codes
$slow = 350 ;Ping time is MS, used for color codes
$lasttime1 = 10 ;Historic data for time
$lasttime2 = 20 ;Historic data for time

$temp = "%temp%\temp.dat"
;--------------------------------------------------------------------------------------------------------
$sleep_min = $sleep_Min
$oldtime=0

:top
CLS
$line = 1
$col2 = 10
$col3 = 25
$col4 = 40
$col5 = 55

$laststore="15ms"

If exist($file) = 1
copy "$file" "%temp%\wanrouters.csv"
else
? "Could not find $file. Script ending"
exit
endif

$nul = open(1,"%temp%\$file",2)
$data = readline(1)

at($line,0) 'Press ' color y+/n '"CTRL-C"' color w/n ' to Exit, AUTO repeat set to $sleep_Min seconds' $line = $line + 1

do
$Store = substr("$data",1,instr("$data",",")-1)
$Store_Router = substr("$data",instr("$data",",")+1,len("$data"))

Shell'%comspec% /c ping -n 1 -w $timeout $Store_Router | find "Reply" > "$temp"'
$q = open(2,"$temp",2) $reply = readline(2) $q = close(2)
if $reply <> ""
$reply_time = substr("$reply",instr("$reply","time")+4,instr("$reply","TTL=")-instr("$reply","time")-5)
at($line+1,0)" "
at($line,0)color g/n "OK" color w/n
select
case val(substr("$reply_time",2,instr("$reply_time","ms"))) <= $fast
color g+/n
case val(substr("$reply_time",2,instr("$reply_time","ms"))) <= $slow
color y+/n
case val(substr("$reply_time",2,instr("$reply_time","ms"))) > $slow
color r+/n
endselect
select
case substr("$reply_Time",1,1) = "="
" " substr("$reply_Time",2,len("$reply_Time")-1) color w/n
case substr("$reply_Time",1,1) = "<"
" $reply_Time" color w/n
endselect
if ($stayon1=1)
$laststore=ReadProfileString ("D:\laptop\cwie5\kix402\last15min.ini", "15_minutes_ago", "$Store")
at($line,$col4)color g+/n "$laststore" color w/n
endif
if ($stayon2=1)
$laststore2=ReadProfileString ("D:\laptop\cwie5\kix402\last30min.ini", "30_minutes_ago", "$Store")
at($line,$col5)color g+/n "$laststore2" color w/n
endif
if (($oldtime=0) or ($oldtime=$lasttime1))
$writeit=WriteProfileString ("D:\laptop\cwie5\kix402\last15min.ini", "15_minutes_ago", "$Store", "$reply_time")
endif
if ($oldtime=$lasttime2)
$writeit=WriteProfileString ("D:\laptop\cwie5\kix402\last30min.ini", "30_minutes_ago", "$Store", "$reply_time")
endif
at($line,$col2)"$store" At($line,$col3)"$Store_Router" $line = $line + 1
else
at($line+1,0)" "
if (($oldtime=0) or ($oldtime=$lasttime1))
$writeit=WriteProfileString ("D:\laptop\cwie5\kix402\last15min.ini", "15_minutes_ago", "$Store", "TIMEOUT!")
endif
if ($oldtime=$lasttime2)
$writeit=WriteProfileString ("D:\laptop\cwie5\kix402\last30min.ini", "30_minutes_ago", "$Store", "TIMEOUT!")
endif
at($line,0)color r+/n "TIMEOUT!" color w/n at($line,$col2)"$store" at($line,$col3)"$Store_Router" $line = $line + 1
endif
if ($oldtime=$lasttime1)
$stayon1=1
endif
if ($oldtime=$lasttime2)
$stayon2=1
endif

$data = readline(1)
until @error <> 0
$nul = close(1)
del "$temp"
color w/n ? "Sleeping for " $sleep_min " sec"
Sleep $sleep_Min
$oldtime=$oldtime+$sleep_Min

?$oldtime
get $x
goto top
exit



Top
#68872 - 2002-08-07 12:01 AM Re: Help with enhancements to Bryces wanreport script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I didn't have patience to read your script but a simple way to thing about it:
you have working script.
k, put it as one routine.
then do a "superscript" which calls for that script.

this way, you can keep the structure as simple as possible.

okey...
the superscript is then pretty simple.
the script is just:
do until $we_have_to_stop<>0
and in it you just count if it is divideable with 5...

I'm not giving you a script yet. just a way of thinking how you can keep it manageable in your or in my mind.
_________________________
!

download KiXnet

Top
#68873 - 2002-08-07 04:33 PM Re: Help with enhancements to Bryces wanreport script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I would create a database (MS Access or SQL) and write the PINGs including timestamp into it. Then you can query historic data as you like by using standard SQL querys.
_________________________
There are two types of vessels, submarines and targets.

Top
#68874 - 2002-08-07 08:45 PM Re: Help with enhancements to Bryces wanreport script
ANOA Offline
Fresh Scripter

Registered: 2002-06-12
Posts: 19
Loc: UK
That would be great to do .... but I am still very much in the learning stage with all this great stuff....

Thanks to you all for the great advice ... I'll post what I come up with when I figure it out (Store history of pings and display extra columns with historic data).

Top
#68875 - 2002-08-07 08:51 PM Re: Help with enhancements to Bryces wanreport script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
mmm...
also using ie timing with that 5 minute thing can be pretty easy...
you know, show the ping table in ie and refresh it every 5mins.
_________________________
!

download KiXnet

Top
#68876 - 2002-08-07 09:04 PM Re: Help with enhancements to Bryces wanreport script
ANOA Offline
Fresh Scripter

Registered: 2002-06-12
Posts: 19
Loc: UK
Please show me the way Lonkero
Top
#68877 - 2002-08-07 09:48 PM Re: Help with enhancements to Bryces wanreport script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I started writing it but then got stucked with stargate.
I'll check more closer your script and how easily the looping can be done.

I'll get back.
might even write the whole thingie if there is no easy way of making the master plan loop.
_________________________
!

download KiXnet

Top
#68878 - 2002-08-08 12:40 AM Re: Help with enhancements to Bryces wanreport script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
getting back at you.
I could debug with your script but too busy.

your first post looks more like the real one.
can you make a your script in the style that it does not output anything?
and if you make it such, what is the var name that is returned.

also, I don't like the idea that user is unable to stop the script whenever he likes so take of the waiting from that script.

all it has to do is to collect info.
the main script will then call it every 60 secs and show info for current and the one of 5 mins ago.

this way the structure of the actual script can be simpler and for me easier to understand.

as, I look at it for 3 mins and then say to myself: "don't even try"

this way it will keep cleaner too.
in the main script you will need just something like:
do
sleep 0.02
...
until kbhit()

hey, this is going to start bother me.
clean up the code a little and send it to me via e-mail and I'll check it in 7 hours when I get to work. ok?

this is not actually hard script but somehow it shows up like one of those when just browsed on the board...
_________________________
!

download KiXnet

Top
#68879 - 2002-08-08 03:50 PM Re: Help with enhancements to Bryces wanreport script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Simpler solution:
Write a script that does the whole thing once and then schedule it with the Task Scheudler to run every 60 seconds or 5 minutes or whatecer interval. The impact on the server should be less.
_________________________
There are two types of vessels, submarines and targets.

Top
#68880 - 2002-08-08 08:25 PM Re: Help with enhancements to Bryces wanreport script
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
I agree with Jens, it would be easier to write whole new code then try and rework my old script.... (i would have done it already... but I got to busy..... well here are some udf's I wrote.)

The ping(,{ping flags}) UDF will return what you see when you do a

shell 'ping kixtart.org -n 1 | find "TTL"' from a commandline

quote:

C:\wanreport>ping www.kixtart.org -n 1 | find "TTL"
Reply from 81.17.37.55: bytes=32 time=218ms TTL=115

$reply = ping("www.kixtart.org")

code:
function Ping($ipaddress, optional $flag)
dim $tempfile, $tempdata, $nul
$tempfile = "" + @ticks + ".dat"

shell '%comspec% /c ping $ipaddress -n 1 $flag | find "TTL" > $tempfile'
$exit=@error
if not @error
$nul = open(1,$tempfile) $tempdata = readline(1) $nul = close(1) del $tempfile
else
$tempdata = "Timeout"
endif
$ping = $tempdata
exit($exit)
endfunction

the Function Loadfile()
will load the contents of the given file into an array

$array = loadfile("computers.csv")
for each $thing in $array
? $thing
next


code:
function loadfile($file)
dim $nul,$count, $line
dim $temparray[10]

if exist($file)
$nul = open(1,$file)
else
exit(1)
endif

while not @error
if $count > ubound($temparray)
redim preserve $temparray[ubound($temparray)+10]
endif
$line = readline(1)
if $line <> ""
$temparray[$count] = $line
$count = $count + 1
endif

loop

if $count > 0
redim preserve $temparray[$count-1]
else
redim perserve $temparray[$count]
endif

$nul = close(1)

$loadfile = $temparray
endfunction

Bryce

Top
Page 1 of 1 1


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

Who's Online
0 registered and 641 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.07 seconds in which 0.027 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