Page 1 of 1 1
Topic Options
#194146 - 09/06/05 03:27 PM can anyone help me then?
itdaddy Offline
Starting to like KiXtart

Registered: 06/12/19
Posts: 145
Loc: Wisconsin

Hey guys
glenn is busy I guess. can anyone one of you gurus help me.
I do not know how to do thebelow I have some of it but
just need help or ag ood reference thanks guys
robert

 Code:
Do

    For Each $Element In $Input
       $count = $count + 1
       Shell "cmd.exe /c ping " + $Element + " -n 1 >> SurpressIT.txt"
       IF (@ERROR  = 0) ? $Element Endif 
       If (@ERROR = 0) remove this element from input array now.
       Then reindex Input array 
       repeat loop because input array is not empty
    Next


While ($input array not empty)




 
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#194147 - 09/06/05 04:15 PM Re: can anyone help me then? [Re: itdaddy]
Shawn Administrator Offline
Administrator
*****

Registered: 99/08/13
Posts: 8608
Just to be clear. You want to loop through a list of hostnames and simply remove the ones that can't be pinged ? Or do you want to keep looping until ALL hostnames in the list get pinged (trying to figure-out if you really need a loop within a loop).
Top
#194148 - 09/06/05 04:28 PM Re: can anyone help me then? [Re: Shawn]
Richard H. Administrator Offline
Administrator
*****

Registered: 00/01/24
Posts: 4945
Loc: Leatherhead, Surrey, UK
Here is an example which works if you don't have the space character in your data:
 Code:
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
#194149 - 09/06/05 05:47 PM Re: can anyone help me then? [Re: Richard H.]
itdaddy Offline
Starting to like KiXtart

Registered: 06/12/19
Posts: 145
Loc: Wisconsin
hey shaun thanks
yes what it is I am building a program where it bounces certain servers names and the instead of me opening up 20 windows i can watch them come up by name as they come up the program would loop the ones that remain in the array until all are taken out of array and thus are successfully up it is a simple prgram. It is almost done but what it is is I reboot servers every so often and I cant fgure out how to keep looping pinging the machiness that are not up yet and then once successful ping display it on screen and keep trying the others until they are all displayed on screen only once. I do not want to wait till all are up then display array. I want them to display as they are successful then keep trying and then once next server is up display that until the exact number of server inputted and rebooted is displayed real-time back to me..I just dont know how to remove an array element from an array in Kix I know in javascript I can do it but am trying to use kixtart then after i get it want to compile it to ane exe using the kixtart compiler...thanks man I do appreciate you guys help will post it here when i am done with it...

Richard H. thank you I will try to read and understand you rendition of my programs tahnks for your help...will post my entire program when I am done for others to see ;\) thank you kindly!
robert(itdaddy)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#194150 - 09/06/05 09:33 PM Re: can anyone help me then? [Re: itdaddy]
Shawn Administrator Offline
Administrator
*****

Registered: 99/08/13
Posts: 8608
Ok understood. I'm just leaving work and will try to take a stab at some code on the train-ride home. If nobody post a solution until then, will post something later tonight ... sounds like a neat project.
Top
#194152 - 09/06/05 10:54 PM Re: can anyone help me then? [Re: Shawn]
Shawn Administrator Offline
Administrator
*****

Registered: 99/08/13
Posts: 8608
k, here's a variation on that first theme ... adding unpingables to a delimited string, than splitting back into the array and looping ...

 Code:
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
#194158 - 09/06/07 01:40 AM Re: can anyone help me then? [Re: Shawn]
itdaddy Offline
Starting to like KiXtart

Registered: 06/12/19
Posts: 145
Loc: Wisconsin
hey shawn
thanks
will try it monday at work
I am not familar with split() but looks like it makes a new array?
I think..but ran thru in my head and it looks like it might work
super...will post entire script when..I thought of it after having
to do this often and hated looking at all the ping replies in multiple DOS
windows..I said to self...self it would be nice to have a script do this
and me just watch names appear when they were up..hee hee hence
bw.exe (bounce watch program) bounce the server watch em come up hee hee.
thanks for your help you the man!
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#194168 - 09/06/08 05:08 PM Re: can anyone help me then? [Re: itdaddy]
itdaddy Offline
Starting to like KiXtart

Registered: 06/12/19
Posts: 145
Loc: Wisconsin
Shawn

it will work great but what I did was remvoe the 'Down' output so it only displays successful pings...great script...

but was wondering how does that
 Code:
 $Array = Split($DownList,"|") 
that work with
 Code:
 $DownList = $DownList + $Hostname + "|" 
....

so it concat a pipe in the array $DownList and then makes a new $Array
I can see that from the $DownList but how does spit() work can you explain how that code works to make it separate the down PCs and then makes the new array? I just cant see how it does it..thanks
Robert;)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#194169 - 09/06/08 05:37 PM Re: can anyone help me then? [Re: itdaddy]
BradV Offline
Seasoned Scripter
****

Registered: 06/08/16
Posts: 666
Loc: Maryland, USA
You're taking an array of hosts, and while the array isn't empty, you are doing:

1. Create a new empty string of downed hosts.
2. For each host in the array
2.a. ping the host
2.b. If you get a reply, state the host is running.
2.c. If not, state the host is down and add the host name to the end of the string of downed hosts along with a delimiter.
3. Create a new array by splitting the downed hosts string on the given delimiter.

Repeat if array isn't empty.

Does that answer your question?

Top
#194170 - 09/06/08 05:44 PM Bounce Watch Program code [Re: BradV]
itdaddy Offline
Starting to like KiXtart

Registered: 06/12/19
Posts: 145
Loc: Wisconsin
Hey thanks Brad V sounds good. thanks for your help. Here is my cheesy bounce watch program..not really complicated but it works and does the trick. I am still learning kix and it is fun...
Thanks to you all for you help all of you kick arse with kix thank you dudes!
 Code:
 

;***************************
;
;  Bounce Watch
;  purpose: Restart servers and watch them come 
;  back up without having to have multiple screens open
;  and eliminates busy screens with echo replies.
;  hence, bounce and watch them come back up.....
;
;***************************




;**************************
;Initialized here.
;*************************

$count = 0
Break On

;************************
;Array prompt here.
;************************

? "Type Input(ex: srv1, srv2):   "
gets $Array
$Array=split($Array,", ")

;*************************************
;Making sure you want to Bounce prompt
;*************************************

? ' '
? "Do you want to Bounce ? (y/n): "  
gets $ansr
if ($ansr = "y")
? ' '
? 'Attempting to ping all servers......Please wait.'
? ' '
Endif

if ($ansr = "n") goto endit Endif

;************************************
;this is the shut down engine
;************************************

For Each $Element In $Array 
           
  Shell "cmd.exe /c shutdown -m \\"+$Element + "-f -r"
  ;? '$Element  -  is shutting down.....' 
 
Next
goto pingIt

;***************************************
; ping engine watch servers come up
;***************************************
:pingIt
? ' '
? 'Do they match above?'
? ' '

?"Scanning.......Please wait for server bounce"?

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!"




goto endit
;***********************************
; Bounce Watch is closing.....
;***********************************
:endit
? ' '
? 'Bounce Watch is closing....'
? ' '
? ' '
? 'This is - The End'

sleep 15
Exit 0
;*********************************
;   End of Bounce Watch
;*********************************




Edited by itdaddy (09/06/08 05:45 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#194171 - 09/06/08 06:16 PM Re: can anyone help me then? [Re: BradV]
itdaddy Offline
Starting to like KiXtart

Registered: 06/12/19
Posts: 145
Loc: Wisconsin
BradV
hey I have a question..the
 Code:
 
While UBound($Array) > 0 
statements
Loop

if the array is 5-0 and zero being an element how does it exit the loop?
if the Ubound($array) say is 5 then that means 6 elements? 5-0 is 6 elements how does it exit??
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#194172 - 09/06/08 07:33 PM Re: can anyone help me then? [Re: itdaddy]
BradV Offline
Seasoned Scripter
****

Registered: 06/08/16
Posts: 666
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:

 Code:
$DownList = "fred|192.168.0.1|barney|7.210.32.7|"
and you issue:
 Code:
$Array = Split($DownList,"|")
I'm pretty sure you will end up with:
 Code:
$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
#194174 - 09/06/08 09:00 PM Re: can anyone help me then? [Re: BradV]
itdaddy Offline
Starting to like KiXtart

Registered: 06/12/19
Posts: 145
Loc: Wisconsin
oh BradV is that what you are saying just my summary below.
yuo are saying I need that last element to be bogus right? so it can finish
the valid array elements right?

it does work perfect though he hee I am a dummy when it reaches

1 > 0 is true
0 > 0 is false then it exits

but I just cant get it thru my head what value is the Ubound($Array) > 0?
it seems that maybe it just knows that the pipe is the delimiter? it is just funny say the $Array element value was this $Array[0] and it equalled
the value of SRV1 to be pinged? would or should it exit the loop cause the array element is zero???? and is false? but for some reason maybe I need the last element to be soomething so it can stop before that point to ping all computernames in the original array? am I making sense? Because the
$Array[5] thru say $Array[0] which is 6 elements in the array so when Ubound() hits zero it exits but maybe I need the last element to be bogus so it can finish all computers in the array huh? am I making sense or am I not getting it?
because it does work....


Edited by itdaddy (09/06/08 09:02 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#194180 - 09/06/09 12:55 PM Re: can anyone help me then? [Re: itdaddy]
BradV Offline
Seasoned Scripter
****

Registered: 06/08/16
Posts: 666
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:
 Code:
$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:
 Code:
$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
#194183 - 09/06/09 01:10 PM Re: can anyone help me then? [Re: BradV]
Glenn Barnas Moderator Offline
KiX Supporter
*****

Registered: 03/01/28
Posts: 4211
Loc: New Jersey
Change Shawn's original code from
 Code:
Else

     ?"$Hostname: DOWN"

     $DownList = $DownList + $Hostname + "|"

    Endif 
to
 Code:
Else

     ?"$Hostname: DOWN"

     $DownList = $DownList + $Delim + $Hostname

     $Delim = "|"

    Endif
and the entire problem of an extra element goes away. The first time through, $Delim is blank, so no delimiter is added, and just the name is added to $DownList. Then Delim is defined, so the next pass adds the delimiter before adding the host. No need to trim the last char before the split this way.

Glenn


_________________________

Actually I am a Rocket Scientist! \:D

Top
#194188 - 09/06/09 03:47 PM Re: can anyone help me then? [Re: Glenn Barnas]
itdaddy Offline
Starting to like KiXtart

Registered: 06/12/19
Posts: 145
Loc: Wisconsin
BradV and Glenn
you guys make me sick how much you know ahhahaah okay it is a good thing
for us newbies ahhaha thanks so much amazing logic and amazing thought process thank you thank you..

Hey what was cool I did a live test yesterday and this is what I found out.
Time is essential here. When I ran the program...it went so fast it ran shutdown and then the ping verify..the machines never had time to have their NICs go offline so it didnt work. I had to add a Time primer of 35 seconds to my code (sleep 35) then it allowed them to go offline..I am sure that is only my cheesy/amateurish way of doing it but I dont know right now what else to do...I know GLenn you mention checking to see if service is running. wish I knew what shut off right away on the machines after the shutdown command was run so I wouldnt have to use the time primer of 35 seconds...at the end of program I might have to include a
shell command of "psinfo \\computername uptime" and loop it to verify each servers uptime is back to zero days so I know for sure that they bounced.
I may for sure include that into this little program..what you think dudes?
Maybe just include this as another verify behind scenes as a check to validated they were bounced like and "if days = 0" kind of test to make sure they were bounced.to makes sure no funny stuff happened...

Cause all I wanted to do was this:

1. check which servers needed bouncing, hence psinfo \\pcname uptime check.
2. enter their names in prompt (or later have it autofill if 21 days or uptime.
3. ask if you want to reboot each y/n
4. run shutdown command in loop to bounce each server
5. wait 35 seconds so they can crash
6. start checking machines with ping command and repeat until all up
only displaying each on the screen as they come up.
7. once done validate their bounce by checking uptime days with psinfo command.
8. mission accomplish go home have a miller genuine draft light!
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Chris S., Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (green78) and 144 anonymous users online.
Newest Members
Keris2112, Jorromans, qrstuv140696, Bloodboy, NIJAKIX
17451 Registered Users

Generated in 0.125 seconds in which 0.07 seconds were spent on a total of 13 queries. Zlib compression enabled.

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