#194148 - 2009-06-05 04:28 PM
Re: can anyone help me then?
[Re: Shawn]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Here is an example which works if you don't have the space character in your data:
Break ON
$Array=Split("06 02 20 11")
CLS
"Hit enter to start" GetS $
CLS
While Join($Array)<>""
AT(1,5) " TIME: "+@TIME
$MISSING=""
$i=0
While $i<=UBound($Array )
If $Array[$i]=Split(@TIME,":")[2]
$FOUND=$FOUND+$ARRAY[$i]+" "
; *** This is the magic where we delete the entry***
$Array[$i]=""
$Array=split(Trim(Join(Split(Join($Array)," "))))
; *** End of magic ***
Else
$MISSING=$MISSING+$ARRAY[$i]+" "
$i=$i+1
EndIf
Loop
AT(3,5) " Hit the following seconds: "+$FOUND+" "
AT(5,5) "Missing the following seconds: "+$MISSING+" "
Sleep (1) ; Slow things down a bit
Loop
@CRLF+"All found..."
|
Top
|
|
|
|
#194152 - 2009-06-05 10:54 PM
Re: can anyone help me then?
[Re: Shawn]
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
k, here's a variation on that first theme ... adding unpingables to a delimited string, than splitting back into the array and looping ...
Break On
$Array = Split("127.0.0.1 127.0.0.1 poop1 127.0.0.1 poop2 poop1")
?"Scanning..."?
While UBound($Array) > 0
$DownList = ""
For Each $Hostname in $Array
If $Hostname
SHELL 'CMD /C PING $Hostname -n 2 | findstr /i "TTL=" >NUL 2>NUL'
If @ERROR = 0
?"$Hostname: RUNNING"
Else
?"$Hostname: DOWN"
$DownList = $DownList + $Hostname + "|"
Endif
Endif
Next
$Array = Split($DownList,"|")
Loop
??">>>Done!"
Exit 0
|
Top
|
|
|
|
#194172 - 2009-06-08 07:33 PM
Re: can anyone help me then?
[Re: itdaddy]
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
|
I was looking at that. I think before you create the array using the split command, you want to delete the last "|". I'm pretty sure when it does the split, it will create an empty last array value. For example, if you have:
$DownList = "fred|192.168.0.1|barney|7.210.32.7|" and you issue: $Array = Split($DownList,"|") I'm pretty sure you will end up with:$Array[0] = "fred"
$Array[1] = "192.168.0.1"
$Array[2] = "barney"
$Array[3] = "7.210.32.7"
$Array[4] = "" If you remove the last "|" before you split, you won't have that last empty element.
Regards,
Brad
|
Top
|
|
|
|
#194180 - 2009-06-09 12:55 PM
Re: can anyone help me then?
[Re: itdaddy]
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
|
Well,
If there is only one computer down, the array (with the code as Shawn presented it) will have two elements. Element 0 will be the name of the down server and element 1 will be null. Since the ubound($array) is equal to 1, the loop will process. I think Shawn included the if $Hostname to eliminate the null value. I would get rid of that if, change the while statement to >= and trim the trailing | before splitting the string:$Downlist = Substr($Downlist, 1, Len($Downlist) - 1) It's just a personal preference. There are always more than one way to program a function.
Write yourself a little script to run some tests. Something like:
$Downlist="smith|barney|wilma|"
$Array=Split($Downlist,"|")
"The upper bound of this array is" + Ubound($Array) ?
For Each $Hostname in $Array
$Hostname ?
Next
"There should be a blank line above if the downlist ended with a |" ? Try a few different scenarios.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|