Hi all,
I am working on a script that will ping a computer and if there is no communication, it will run a script that sends me an e-mail. So far, I have figured out the opposite (how to see if there is no communication) but I want to keep repeating until there is no communication. What would be the simplest (and least processor intensive) of doing this?
Is it bad to have basically an endless loop going? So, if there is communication it will continue running? Thank you so much for your help.
--SCRIPT (corrected)
try
-- (0) check server's response
set max_retry to 60
set k to 0
repeat while (do shell script "ping -c 1 192.168.112.107 2>&1; exit 0") does not contain "100% packet loss"
delay 5
set k to k + 1
if k > max_retry then error "Server is not responding for predefined period." number 8000
end repeat
-- If there is no communication then switch to other output and send e-mail
on error errs number errn
display dialog errs & " " & errn with icon 2
--error errs number errn
end try
--END OF SCRIPT
on idle
try
if (do shell script "ping -c 1 192.168.112.107 2>&1; exit 0") contains "100.0% packet loss" then
-- Server not responding, send email.
my SendEmail()
end if
on error errs number errn
display dialog errs & " " & errn with icon 2
end try
return 5 -- Delay in seconds
end idle
on SendEmail()
-- Sending email code
end SendEmail
Save it as a stay-open application and open it. The code will be run every 5 seconds until you quit the application.
Is there a way to check if programs on another connected computer are running through Applescript. Basically, I would like to tighten down my script to where if a program quits running on another computer, the backup would take over.
Yes. it is running 10.5.6 but not yet Snow Leopard. I was hoping to dial down the ping to see if the app would be running instead of only the computer, because the computer could still be running, but the app itself could have failed.