Script for pinging remote computer

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
leader
Newbie
Posts: 1
Joined: Fri May 16, 2003 4:27 pm

Script for pinging remote computer

Post by leader » Fri May 16, 2003 4:36 pm

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

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri May 16, 2003 11:32 pm

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:
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
Notes:
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!

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon May 19, 2003 11:23 pm

Hi Bob,

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.

Guest

Post by Guest » Tue May 20, 2003 12:10 am

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

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue May 20, 2003 12:26 am

:oops: Sorry, I was not logged in when I sent the last reply that modified Armstrong's modification of my script.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts