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