#116902 - 2004-03-26 06:51 PM
WSHPING()/WSHPIPE() - Question
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
I created a logging structure to look to see if a set of servers is either down or up.. However, if I use WSHPING()/WSHPIPE(), it logs 5 down or 5 up for each server. What I want to know is if the server is down, we would see a DOWN or if "Destination host is unreachable" it is also DOWN, but I only want to show only one status for each server.
Here is the code -
Code:
CLS
BREAK ON
;WHILE EXIST(@scriptdir+'\srvavail.kix')
$lf=@scriptdir+'\serverstate.csv'
$logdata=@date+','+@time+@crlf
LOGGER($lf,$logdata)
SRVAVAIL($lf)
$excel=READVALUE('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe','')
RUN $excel+' '+$lf
;LOOP
FUNCTION SRVAVAIL($lf)
DIM $i,$j,$amerdt,$chk,$rc,$srv,$time,$tcheck,$ortime,$status,$body,$recip
$amerdt=split(@date,'/')[1]+'/'+split(@date,'/')[2]+'/'+split(@date,'/')[0]
$xlsfile = @scriptdir+'\servers1.xls'
$oxl = Createobject("Excel.application")
; -- Open the Excel Work book
; -- Note: if you do not include a variable on the next line (e.g. $rc =), it will error
$rc=$oxl.workbooks.open($xlsfile)
$rc=$oxl.sheets('iDev-DMZ').Activate
$nrow = 1 ; -- Assume Row one is column Headings
WHILE $oxl.cells($nrow, 1).value <> "" ; -- If this is not NULL, keep going
$nrow = $nrow + 1 ; -- Data Starts on row two and add 1 each time
IF $oxl.cells($nrow, 1).value = ""
?"Script is Complete"
SLEEP 4
$oxl.quit
$oxl = ""
RETURN
ENDIF
; -- Get the value of the first field
$srv = $oxl.cells($nrow, 1).value
?$srv
;?$sectionkey+' '+$status
?'Checking Server: '+$srv
$rc=WshPipe('%COMSPEC% /C PING -n 5 '+$srv,1)
FOR EACH $line IN $rc
IF instr($line, "Destination Host Unreachable") OR @error<>0
? $line
$logdata=$i+',DOWN'+@crlf
LOGGER($lf,$logdata)
ELSE
$logdata=$i+',UP'+@crlf
LOGGER($lf,$logdata)
ENDIF
NEXT
LOOP
ENDFUNCTION
Thanks,
Kent
|
|
Top
|
|
|
|
#116903 - 2004-03-26 07:14 PM
Re: WSHPING()/WSHPIPE() - Question
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Looks like you're getting five hits on "Destination Host Unreachable." How about limiting the number of ping requests...
Code:
$rc=WshPipe('%COMSPEC% /C PING -n 1 '+$srv,1)
|
|
Top
|
|
|
|
#116904 - 2004-03-26 07:22 PM
Re: WSHPING()/WSHPIPE() - Question
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Yeah.. I was thinking that too.. However, when we are trying to verify a server (we have one center on a DSL Link) it may take a series of responses to go through.
Kent
|
|
Top
|
|
|
|
#116906 - 2004-03-26 07:43 PM
Re: WSHPING()/WSHPIPE() - Question
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
That makes sense..
Thanks.
Kent
|
|
Top
|
|
|
|
#116907 - 2004-03-26 07:50 PM
Re: WSHPING()/WSHPIPE() - Question
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Something like...
Code:
FOR EACH $line IN $rc IF instr($line, "Destination Host Unreachable") OR @error<>0 $status='DOWN' ELSE $status='UP' ENDIF NEXT $logdata=$i+','+$status+@crlf LOGGER($lf,$logdata)
Should return UP as long as the last reply is good. I guess if the last reply is no good then you would want it to be DOWN anyways right?
|
|
Top
|
|
|
|
#116908 - 2004-03-26 08:08 PM
Re: WSHPING()/WSHPIPE() - Question
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
search here for my kpinger script..
|
|
Top
|
|
|
|
#116909 - 2004-03-26 08:23 PM
Re: WSHPING()/WSHPIPE() - Question
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Rad,
Tried to find your KPINGER here and do not see it.
Your site gives me four oh fours.
Kent
|
|
Top
|
|
|
|
#116910 - 2004-03-26 10:13 PM
Re: WSHPING()/WSHPIPE() - Question
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
try this...
Code:
$num = 5 Shell '%comspec% /c ping -n $num 10.10.0.87 | find "TTL=" > nul' If not @ERROR ? "At lease one ping out of $num was good" Else ? "no ping reply" EndIf
as long as the FIND command finds one item, @error = 0
|
|
Top
|
|
|
|
#116911 - 2004-03-26 10:56 PM
Re: WSHPING()/WSHPIPE() - Question
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
here is the file
www.wheelerfam.com/kixtart/kpinger.kix
it is a bit old, so some of the coding practices are a bit primitive by my current standards
|
|
Top
|
|
|
|
#116912 - 2004-03-27 12:45 AM
Re: WSHPING()/WSHPIPE() - Question
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Bryce,
Thanks - works like a charm!
Kent
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 756 anonymous users online.
|
|
|