Hi,
I need some help in creating a script.
I have a few remote controlled computers, which I access through a server connection. They are connected to a web-controlled remote reboot powerstrip, in case one of them "freezes" and requires rebooting.
I want to create a script in which I periodiaclly "ping" each computer, and if the connection is timed out I can then automatically trigger a remote reboot to that computer. I have managed to create a macro that will open a comand prompt window and will ping a certain IP address. How do I create a conditional command that if the words "Timed Out" appear on the screen then, continue on to the next command, and if theses words do not apear to stop?
Thanks for your help,
Noam Leader
Rockefeller University
Script for pinging remote computer
Moderators: JRL, Dorian (MJT support)
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
HI Leader.....here is an approach that may work for you.
You could do a normal ping and redirect results to a file. Use FIND /C with PING to filter the results. You will end up with a file that shows the number of lines with the phrase you are looking for. Then read the file and check results, 0 = phrase not found.
Something like this:
1. This example is untested, off the top of my head.
2. You could also make the IP a variable and loop through a string of IPs.
3. You could also check for No Reply, or for other phrases you are interested in, and respond to each condition differently. Just make a loop to do ping | find > testfile for each phrase, check result, and continue loop for next phrase until all phrases are checked. Could break out of loop as soon as one phrase shows disconnect.
Hope this helps....good luck
You could do a normal ping and redirect results to a file. Use FIND /C with PING to filter the results. You will end up with a file that shows the number of lines with the phrase you are looking for. Then read the file and check results, 0 = phrase not found.
Something like this:
Notes:Label>PingTest
Run Program>command.com /c ping 192.168.100.50 | find /c "timed out" > pingtest.txt
ReadLn>pingtest.txt,1,Count
If>Count>0,TimedOut
//Enter x=seconds for delay before repeating pingtest
Wait>x
Goto>PingTest
Label>TimedOut
Message>192.168.100.50 Timed Out
Goto>End
Label>End
1. This example is untested, off the top of my head.
2. You could also make the IP a variable and loop through a string of IPs.
3. You could also check for No Reply, or for other phrases you are interested in, and respond to each condition differently. Just make a loop to do ping | find > testfile for each phrase, check result, and continue loop for next phrase until all phrases are checked. Could break out of loop as soon as one phrase shows disconnect.
Hope this helps....good luck
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
Hi Bob,
Personally, I'm not a great fan of infinite iterations. To impose the limit, I add a few commands in your script:
Instead, I would use Macro Scheduler Main Menu to schedule the ping test, maybe, every 10 minutes.
Personally, I'm not a great fan of infinite iterations. To impose the limit, I add a few commands in your script:
Let>Count=0
Label>PingTest
Run Program>command.com /c ping 192.168.100.50 | find /c "timed out" > pingtest.txt
ReadLn>pingtest.txt,1,Count
If>Count>0,TimedOut
//Enter x=seconds for delay before repeating pingtest
Wait>x
Add>Count,1
If>Count>8,End
Goto>PingTest
Label>TimedOut
Message>192.168.100.50 Timed Out
Goto>End
Label>End
Instead, I would use Macro Scheduler Main Menu to schedule the ping test, maybe, every 10 minutes.
Thanks Armstrong, but I need to modify your version now. You are using Count which I was already using as the result of reading the file. So I will change your Count to Loops
Also a good suggestion to schedule to run every X mins as an option to having the macro run continuously and testing every Wait>x seconds. What a team!Let>Loops=0
Label>PingTest
Run Program>command.com /c ping 192.168.100.50 | find /c "timed out" >
pingtest.txt
ReadLn>pingtest.txt,1,Count
If>Count>0,TimedOut
//Enter x=seconds for delay before repeating pingtest
Wait>x
Add>Loops,1
If>Loops>8,End
Goto>PingTest
Label>TimedOut
Message>192.168.100.50 Timed Out
Goto>End
Label>End
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact: