Mount Volume Throws Error when server not available

Greetings,

I am trying to write a script that allows me to check the status of a number of mounted volumes and remount them if they get disconnected. The usual reason for disconnection is that the server got rebooted. I run the script every 5 minutes using CRON and it works fine. The only problem is if the script runs before the server comes back up…the mount volume command throws an error that apparently cannot be trapped or dismissed. If the server is unavailable, i get a dialog box that says “Connection Failed” No response from the server. Please try again.

There is an OK button on it and the script will not continue until the OK button is clicked. If you click it…the script tries to mount the volume again and throws the same error if the server is not yet back up. I must click OK a second time to ge the script to finally move on the next volume.

Does anybod know how to get rid of this error?

The command I am using to mount the volume is:

try
with timeout of 10 seconds
mount volume “afp://server/volume” as user name “name” with password “password”
end timeout
end try

Thanks in advance for any help.

You might want to consider something like one of the following:

tell application "Finder" 
repeat until (exists disk "Files") 
activate application "Finder" 
with timeout of 20 seconds 
mount volume "afp://server/volume" & "/Files" as user name "myName" with password "myPass" 
end timeout 

Finder is not always necessary:


set list_disks to list disks
	set ThisVolume to "afp://server"
	try
		if (list disks) does not contain "mountVol" then mount volume ThisVolume
	end try
	try --this will reveal the drive in a Finder window 
		reveal folder "mountVol"
	end try

In a Handler:


on mountVol() 
   set mVol to list disks 
   set volId to item 1 of mVol 
   repeat with volId in mVol 
      if volId as text = "mount_VOLUME" then 
         return true 
      end if 
   end repeat 
   return false 
end mountVol

I use this one the most in my scripts:

tell application "Finder"
		set mounted_Disks to list disks
		--display dialog result as string
		--set mounted_Disks to every disk whose (ejectable is true)
		if mounted_Disks does not contain "INGEST" then
			mount volume "cifs://10.10.10.12/mount_Vol/" as user name "username" with password "password"
		end if
	end tell

There are otherr ways, too, of mounting a Volume. Good Luck

Thank you for your reply…however it did not address my specific issue. Allow me to be more clear.

I can check for and mount the volumes just fine WHEN THE SERVERS ARE AVAILABLE. The problem is the script dies at the mount volume command IF THE SERVER IS DOWN.

If I run this command:
mount volume “afp://nonexistenserver/nonexsistentvolume” as user name “fake” with password “fake”

The mount volume command (NOT MY SCRIPT) will generate a connection error and will prompt with a dialog box that I must answer “OK” to in order for the script to continue.

Keep in mind…the server does actually exist…it is just temporarily unreachable. So what I need is either a way around this weird behavior of the mount volume command or a way to check that the server is running before I try and mount the volume.

Thank you again for your help.

i had to do something similar for ical scheduled timemachine backups. this script will close the window a bit, but not completely. it uses “ping” to determine if the host is available. there is still the chance, when the machine is starting up, that it will be pingable, but not able to mount the drive.



set mountTm to true
set runBackup to true

tell application "Finder"
	set disklist to list disks
	
	repeat with i from 1 to number of items in disklist
		if item i of disklist is equal to "timemachine" then
			set mountTm to false
		end if
	end repeat
end tell

set ping_result to (do shell script "ping -c 1 mako; echo none")
if ping_result is equal to "none" then
	set mountTm to false
	set runBackup to false
end if

if mountTm then
	ignoring application responses
		mount volume "smb://mako/timemachine"
	end ignoring
end if
if runBackup then
	try
		do shell script "/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper"
	end try
end if


Hi John,

nice to meet you here again :slight_smile:

Your script is quite complicated, this is an easier version
(regardless of the problem to make Time Machine backups on network volumes ;))


if "timemachine" is not in (do shell script "ls /Volumes") then
	try
		mount volume "smb://mako/timemachine"
	on error
		return -- abort the script
	end try
end if
try
	do shell script "/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper"
end try

Hello,

I’ve been struggling with the unsuppressable error-message for a while now, but can’t seem to find a real solution anywhere.

While the ping-solution test for the server works, there’s still a chance the server is not offering the volume yet (like John says), is there a way to test for the volume being available as well before using AS’s “mount volume” command?

B.t.w., the command “open location” has a parameter “without error reporting”, which seemed promising, but this command does not seem to work in my particular situation

-- this works, IF the volume is available on the network, otherwise it displays the uninterceptible modal error dialog
mount volume "afp://workstation:workstation@192.168.0.27/Backup"

-- this does nothing at all
open location "afp://workstation:workstation@192.168.0.27/Backup"

I need to set up a number of machines with unsupervised backups, so any help on this would be more than welcome.

Hi,

look into this thread