I am trying to write a script that monitors mounted network volumes. If a volume becomes dismounted, the script will check to see if the remote host is up and running before trying to re-mount the volume. The script I wrote works fine. It uses a ping command to determine if the host is up or down. However, I run this script using the crond. Cron apparently does not like the way i wrote the script because it never re-mounts my volumes.
Does anybody know why this would be or have a better way to go about doing this.
The command that files during the cron run is
set Result to do shell script “ping -c 1 host.domain.com”
set AppleScript’s test item delimiters to “,”
set Test to the second text item of Result
set Number to the first word of Test
if number is “1” then
If I remove the above code, the cron job will mount the volume just fine.
Thank you kindly,
The computers I am testing this on are all running 10.3.9.
First, you’ve got typo (“test item” instead of “text item”) and you’re trying to use reserved words as variables (result & number). Finally, you don’t trap any errors that may occur if the ping fails. Try this:
property host_domain : "host.domain.com"
set domain_active to my ping_domain(host_domain)
return (((do shell script "ping -c 1 " & the_domain)'s paragraph 5's word 4) = "1")
The typo was only in the message I posted, not in the code itself. I do not trap any errors…but in my testing I was pinging a box that I new was running…so no error should have been thrown.
In addition, the script worked just fine when run from the command line using osascript myscript.scpt. If I went to cron and scheduled it to run…the volume never got mounted. If I removed the part with the ping and let cron run the script…the missing volume would mount.
What I am looking for is either a reason why the script would run when manually run, but not under cron…or another/better way to test and see if a host is alive or down.