Eject Drives at VPN Disconnect or at Sleep

rhs615
New Contributor III

We currently have a script that prompts user for Username and Password, passes it through to the VPN, connects the VPN, and then mounts smb shares. This script is delivered through the Self Service store.

If a user connected to the VPN with mounted drives loses internet connection, or closes the lid of their laptop, the VPN disconnects and the drives remain mounted. This freezes finder for close to 5 minutes until the drives finally eject themselves and finder force quits multiple times.

Has anyone gotten any kind of sleep triggers or lid close triggers to work? If we had that as a trigger, we could eject drives using a script or somethng...

5 REPLIES 5

mm2270
Legendary Contributor III

Check out SleepWatcher http://www.bernhard-baehr.de
I haven't used it in some time, but its a small utility that can trigger scripts or unix commands at sleep or wake. From the developer page, it looks like it works under 10.7. It may do exactly what you're looking for.

Mike

tkimpton
Valued Contributor II

Hi Mike

I'm looking for a similar solution to disconnect network shares just before going to sleep. I have tried sleep watcher but by default the rc.sleep script points to ~/.sleep and has some syntax in there which only looks for it.

Have you managed to use this successfully and if so what syntax have you used in your rc.sleep?

Thanks

tkimpton
Valued Contributor II

Im trying to eject everything except optical media

A starting point is here

http://forums.macrumors.com/showthread.php?t=852549

http://vocaro.com/trevor/blog/2007/02/11/a-set-of-scripts-to-unmount-drives-before-sleeping/comment-...

at the moment i am just using

tell application “Finder” eject (every disk whose ejectable is true)
end tell

but its not good for hire equipment if someone has a CD in ther :(

Any thoughts?

mm2270
Legendary Contributor III

@tkimpton, the script in the second link isn't going to work, as its using diskutil, which won't list any network mounted shares. ls -l /Volumes/ will list them, but its fragile and a little tricky to get the proper volume names from that.

In the past when I used ARD, I used to issue a 'umount /Volumes/' or 'umount -A' to client systems when I needed to quickly unmount everything on them. This of course would throw an error since it can't unmount the boot volume, but it would proceed to unmount everything else.
umount has a -t (type) flag that supposedly allows you to only eject volumes of certain types, such as smb or afp shares, but when I tested it out on an SMB share I had mounted it did absolutely nothing, so I don't know if it works, or maybe its dependent on how the share is read/perceived by the OS.

As for SleepWatcher, truthfully I haven't set it up or used it in years now and my memory ain't what it once was, so I'm a bit fuzzy on how it worked and how I used it. I believe you can configure it to look at any script you want, but the local user rc.sleep may have been a requirement for it to all work. I don't recall now.

tkimpton
Valued Contributor II

Thanks Mike. I will use what I have for now and if people moan about CDs / DVDs ejecting then too bad ;)

SleepWatcher documentation could be better.

Basically forget the rc.sleep and rc.wake stuff and just take the launch daemon and change it to point to you executable scripts and that's it.

Instead it's got a rather long Read me which is really not necessary.

Great utility though.