PDA

View Full Version : Unmount share after copy


michael.green
11-27-2006, 03:30 PM
One of the tasks I use SD! for is daily copies of my user directory to a SimpleShare NAS. I have seven sparseimage files. Each one is updated on its day of the week in the middle of the night.

My question is: what is the preferred way to unmount the share after SD! is done?

I know that SD! unmounts the relevant sparseimage file. But the share is still mounted and I would like an automatic way of unmounting that.

Thanks!

dnanian
11-27-2006, 04:35 PM
You could try to either modify the "schedule driver" (inside the application package) to do it, or write a little shell script that tosses an event into the background, waits 20 seconds or so and then unmounts...

michael.green
11-28-2006, 01:45 AM
I need a little more hand holding, I'm afraid.

Here's the shell script I have (name: unmountTheShare)
#!/bin/sh
sleep 20
umount /Volumes/TheShare

Here's the error I get in SD!'s Phase 3:
| 10:31:36 PM | Info | ...ACTION: Running shell script unmountTheShare
| 10:31:36 PM | Info | ......COMMAND => Invoking After Copy shell script: /Users/michaelgreen/Library/Scripts/unmountTheShare
| 10:33:36 PM | Error | umount: unmount(/Volumes/TheShare): Resource busy

I see what the problem is. SD! hasn't unmounted the sparseimage file yet.

I gather I'm missing the 'event tossed into the background'. But I don't know how to do that, that is, toss an event into the background. I assume it's just ... one ... more ... line.

Thanks again.

dnanian
11-28-2006, 11:51 AM
Something like this:

#!/bin/sh
nohup /bin/bash -c "sleep 20; diskutil unmount /Volumes/TheShare" &

michael.green
12-09-2006, 12:56 AM
Thanks for the suggestion. SD! no longer gives me an error, but the share remains mounted.

Looking up diskutil in an edition of Mac OS X in a Nutshell (for 10.2), I see it says that diskutil needs to run with "special permissions". Perhaps that's what's amiss. Changing my account, the one that SD! runs under, to administrator doesn't seem to do the trick, though.

Does it have to run as root? And, if so, how do I make that happen?

Is there something else I should look into as a diagnostic matter?

Thanks again for all your help.

dnanian
12-09-2006, 09:14 AM
No, it's already running with escalated permissions. Does your drive perhaps have a space in its name or something like that? Check the Console to see if there are any errors.

michael.green
12-09-2006, 11:05 AM
I kept the generic "SimpleShare" for the drive name.

Would capitalization matter? For the Finder's Connect to Server dialog, everything is lowercase (smb://simpleshare/mjg/). But in the sidebar area, the share is MJG. (I tried running the script manually, using BBEdit's "run script" menu entry, with it spelled both "mjg" and "MJG" but that didn't seem to make a difference, for what it's worth.)

SD! runs at 11:47 every night. Here's what look like relevant console messages from around that time for the past three nights. One in particular looks to my very untrained eye as if it stands out:

mount_smbfs: spnego blob2principal error 1

Mac OS X Version 10.4.8 (Build 8L127)
2006-12-05 11:04:21 -0800
Dec 5 20:50:55 MJGsPowerBook configd[74]: SecKeychainFindGenericPassword err= -25308 ( =0xffff9d24, secErrStr=User interaction is not allowed. ) (current= Esmerelda)
Dec 5 23:45:07 MJGsPowerBook configd[74]: SecKeychainFindGenericPassword err= -25308 ( =0xffff9d24, secErrStr=User interaction is not allowed. ) (current= Esmerelda)
mount_smbfs: spnego blob2principal error 1

Dec 6 23:45:06 MJGsPowerBook configd[74]: SecKeychainFindGenericPassword err= -25308 ( =0xffff9d24, secErrStr=User interaction is not allowed. ) (current= Esmerelda)
mount_smbfs: spnego blob2principal error 1


Dec 7 23:45:07 MJGsPowerBook configd[74]: SecKeychainFindGenericPassword err= -25308 ( =0xffff9d24, secErrStr=User interaction is not allowed. ) (current= Esmerelda)
mount_smbfs: spnego blob2principal error 1
2006-12-07 23:52:15.970 SyncServer[10360] A Sync Server is already running on this computer, exiting process.
2006-12-07 23:56:59.698 Translator[10418] Invoked to sync conduit com.apple.Safari for entityNames: com.apple.bookmarks.Folder,com.apple.bookmarks.Boo kmark
2006-12-08 00:52:13.840 SyncServer[10639] A Sync Server is already running on this computer, exiting process.
2006-12-08 00:55:02.563 Translator[10642] Invoked to sync conduit com.apple.Safari for entityNames: com.apple.bookmarks.Folder,com.apple.bookmarks.Boo kmark
Dec 8 01:45:16 MJGsPowerBook DirectoryService[86]: SafeOpen::Call to netinfo_open was with argument domain name: .. and lasted 3 seconds while timeout was 3



2006-12-08 21:49:47.418 SyncServer[11060] A Sync Server is already running on this computer, exiting process.
2006-12-08 21:52:49.930 Translator[11071] Invoked to sync conduit com.apple.Safari for entityNames: com.apple.bookmarks.Folder,com.apple.bookmarks.Boo kmark
Dec 8 23:45:04 MJGsPowerBook configd[74]: SecKeychainFindGenericPassword err= -25308 ( =0xffff9d24, secErrStr=User interaction is not allowed. ) (current= Esmerelda)
mount_smbfs: spnego blob2principal error 1
2006-12-09 00:29:51.172 SyncServer[11511] A Sync Server is already running on this computer, exiting process.
2006-12-09 00:32:04.228 Translator[11516] Invoked to sync conduit com.apple.Safari for entityNames: com.apple.bookmarks.Folder,com.apple.bookmarks.Boo kmark
2006-12-09 01:29:53.317 SyncServer[11551] A Sync Server is already running on this computer, exiting process.
2006-12-09 01:31:51.339 Translator[11556] Invoked to sync conduit com.apple.Safari for entityNames: com.apple.bookmarks.Folder,com.apple.bookmarks.Boo kmark
2006-12-09 02:29:55.544 SyncServer[11592] A Sync Server is already running on this computer, exiting process.
2006-12-09 02:34:18.609 Translator[11598] Invoked to sync conduit com.apple.Safari for entityNames: com.apple.bookmarks.Folder,com.apple.bookmarks.Boo kmark
2006-12-09 03:29:54.964 SyncServer[11789] A Sync Server is already running on this computer, exiting process.
2006-12-09 03:30:18.523 Translator[11793] Invoked to sync conduit com.apple.Safari for entityNames: com.apple.bookmarks.Folder,com.apple.bookmarks.Boo kmark
2006-12-09 04:29:57.673 SyncServer[11828] A Sync Server is already running on this computer, exiting process.
2006-12-09 04:33:18.195 Translator[11837] Invoked to sync conduit com.apple.Safari for entityNames: com.apple.bookmarks.Folder,com.apple.bookmarks.Boo kmark
2006-12-09 05:29:59.800 SyncServer[11871] A Sync Server is already running on this computer, exiting process.
2006-12-09 05:34:58.018 Translator[11877] Invoked to sync conduit com.apple.Safari for entityNames: com.apple.bookmarks.Folder,com.apple.bookmarks.Boo kmark
2006-12-09 06:30:02.058 SyncServer[11910] A Sync Server is already running on this computer, exiting process.
2006-12-09 06:30:58.100 Translator[11915] Invoked to sync conduit com.apple.Safari for entityNames: com.apple.bookmarks.Folder,com.apple.bookmarks.Boo kmark
2006-12-09 07:30:04.444 SyncServer[11949] A Sync Server is already running on this computer, exiting process.
2006-12-09 07:31:55.123 Translator[11954] Invoked to sync conduit com.apple.Safari for entityNames: com.apple.bookmarks.Folder,com.apple.bookmarks.Boo kmark

dnanian
12-09-2006, 11:16 AM
Capitalization would likely matter with the command, yes. What I'd suggest is running it yourself, in Terminal, until you get it to work as expected...

michael.green
12-09-2006, 09:32 PM
1. ls /Volumes reveals that it's "mjg", not "MJG"

2. Here's my testing procedure:
a. mount mjg using the Finder in my non-administrator account
b. login via Terminal to an administrator account.
c. sudo diskutil unmount /Volumes/mjg
d. I get a mini-manual for diskutil. (This happens if I use diskutil in the terminal in one of six ways -- (i) from my account, from an administrator account, (ii) using sudo first or (iii) not; and the same, only calling the volume "MJG".)

Disk Utility Tool
Usage: diskutil [mount(Disk)|unmount(Disk)|eject] <force>
[Mount Point|Disk Identifier|Device Node]
Mount, unmount or eject local disks or volumes.
force is only valid on unmount or unmountDisk.
Example: diskutil unmount /Volumes/SomeDisk


3. diskutil list doesn't produce anything that looks like the volume I'm trying to unmount. It's 135 GB in size.

/dev/disk0
#: type name size identifier
0: Apple_partition_scheme *55.9 GB disk0
1: Apple_partition_map 31.5 KB disk0s1
2: Apple_Driver43 28.0 KB disk0s2
3: Apple_Driver43 28.0 KB disk0s3
4: Apple_Driver_ATA 28.0 KB disk0s4
5: Apple_Driver_ATA 28.0 KB disk0s5
6: Apple_FWDriver 256.0 KB disk0s6
7: Apple_Driver_IOKit 256.0 KB disk0s7
8: Apple_Patches 256.0 KB disk0s8
9: Apple_HFS Themistocles 55.9 GB disk0s9


4. The graphical application Disk Utility, doesn't show mjg, either in my account or the administrator account. In other words, I couldn't unmount the volume using the graphical application if I tried.

5. Do points 2-4 add up to the following: diskutil doesn't see the volume I'm trying to unmount using diskutil? If so, I can see why there would be a problem.

Thanks. I hope I'm not being too dense. But I am learning a few things along the way ... I think.

dnanian
12-10-2006, 12:26 AM
Try "eject" instead of "unmount" and see if that works.

michael.green
12-10-2006, 11:35 AM
No luck. I logged in via the terminal to the administrator account and tried:

1. sudo eject /Volumes/mjg
2. sudo eject /Volumes/MJG
3. sudo unmount force /Volumes/mjg
4. sudo unmount force /Volumes/MJG
5. sudo eject force /Volumes/mjg
6. sudo eject force /Volumes/MJG

Each time, I got the same mini-manual for diskutil

NB: the volume "mjg" was mounted by SD! last night. Don't know if that makes a difference or not.

Thanks, as always.

dnanian
12-10-2006, 11:41 AM
OK. My mistake: diskutil will only eject local volumes. This is a network mount. So, try:

#!/bin/sh
osascript <<77
tell application "Finder" to eject "the-volume-name"
77

michael.green
12-10-2006, 02:12 PM
And away the share goes! That did the trick. Yay!

Let me see if I understand (a) what happened and (b) what has to be done next.

(a) What happened?
(i) osascript = we're sending something to a program other than the shell. Applescript and the Finder, I think.
(ii) <<77 = we're starting here, 77 is a delimiter
(iii) tell the Finder to eject the volume -- that's what we want the other programs to do.
(iv) 77 = the other delimiter; that's the end of what we're sending to the other program.

(b) Now what comes next? We need to:
(i) wait for 20 seconds or so
(ii) run in the background.
So ...

#!/bin/sh
sleep 20
osascript <<77
tell application "Finder" to eject "mjg"
77


The second line waits for 20 seconds; that works in my testing. Task (b)(i) done.

But (b)(ii) is stumping me. Putting & or bg in various parts of this script produces errors. If I had to guess (and I do), it's that there should be something between the 77s that accomplishes this. But neither my books nor the internet is helping much.

dnanian
12-10-2006, 04:36 PM
I think you'll now be able to do this with a single line, since the mini-script worked, the tricky thing being escaping things properly, and I couldn't figure it out. So put the eject in a little saved script:

tell application "Finder" to eject "mjg"

save as text or a compiled script, and do:

#!/bin/sh
nohup /bin/bash -c "sleep 20; osascript path/to/the/script/file" &

michael.green
12-10-2006, 06:13 PM
Looks like we have a winner. I just ran Sunday's SD! job, took a walk, and came back to see SD! is done and the share is unmounted.

Thanks a million. There was no way I was going to hit on that on my own.

dnanian
12-10-2006, 06:23 PM
Teamwork! ;)

eriolarda
12-11-2006, 09:08 PM
Here's how I got it to work. The idle handler in the AppleScript checks whether SuperDuper is running; if so, it comes back after 2 secs to check again. When SD is gone, that must mean the share isn't being used any more. So then it ejects, then quits itself. (Replace "YourShare" with the name of your share.)

The Applescript needs to be saved as App, with "stay open" option active.


global BackupInProgress, BackupPartPresent

on goodbye()
quit
end goodbye

on idle
if BackupInProgress is false then

tell application "Finder"
if (exists the disk "YourShare") then
eject "YourShare"
set BackupPartPresent to false

end if
if (exists the disk "YourShare") then

end if
end tell
goodbye()
else
tell application "System Events" to (creator type of processes) contains "SdPr"

set BackupInProgress to the result
-- beep 1
--return 2

end if
return 2

end idle
on run
set BackupPartPresent to true

tell application "System Events" to (creator type of processes) contains "SdPr"

set BackupInProgress to the result

idle
end run


Since SD can't seem to call scripts that stay open, I have this snippet called from SD (replace "/path/to/TheAppleScript.app" with path to where your Applescript resides)



open ~/path/to/TheAppleScript.app
exit




For some reason, I couldn't get it to work with the "osascript" command.

Actually this feature should really be built in!

xtian666
01-02-2007, 11:25 AM
I think you'll now be able to do this with a single line, since the mini-script worked, the tricky thing being escaping things properly, and I couldn't figure it out. So put the eject in a little saved script:

tell application "Finder" to eject "mjg"

save as text or a compiled script, and do:

#!/bin/sh
nohup /bin/bash -c "sleep 20; osascript path/to/the/script/file" &

The applescript works great, but how do I impliment the shell command into SuperDuper?

dnanian
01-02-2007, 11:26 AM
Set it as the "after copy" shell script in the Advanced tab of Options.

xtian666
01-02-2007, 11:36 AM
Set it as the "after copy" shell script in the Advanced tab of Options.

Obscenely fast response - you guys rock :-)

But a dense reply... I have the applscript saved and it works fine when I manually launch it. The shell command I assumed would be copied and pasted into the "after copy" section under the Advanced tab. However, this brings up an open dialog box so do I just save the shell command as a text file and then point the "after copy" to that file?

dnanian
01-02-2007, 11:39 AM
Yes. You save it as a text file, mark it as executable (chmod +x the-file), and point to that.