PDA

View Full Version : Execute script on external mount


John.Deery
05-23-2008, 12:34 PM
Hello all,

I'm trying to develop a script that will check for a hidden file on a volume. The purpose is so that when someone mounts an external drive (usb or firewire), the script will run and if the file is not found, it will reject the mount.

The reasoning behind it is that I work for a school district and we're noticing more and more illegal software entering our system via external hds. The plan is to have a station set up for a virus and visible scan of the drive's contents, and once verified, a program will be run that will put this hidden file onto the drive. Once mounted, the hidden file will be deleted.

I'm developing the script for both mac and PC, but so far I haven't been able to find much about hooking into the mac mount volume process. I found some information on an Ubuntu forum about uDev rules, but I wasn't able to find anything similar on the mac side.

Any pointers would be much appreciated.

JD

cwtnospam
05-23-2008, 01:08 PM
Drives are mounted in /Volumes so you'll want to set up launchd to watch that folder. Then something like this script would work:
#!/bin/bash
if [ -d "/Volumes/SomeDisk" ]; then
# Code to look for hidden file in /Volumes/SomeDisk
fi

John.Deery
05-23-2008, 01:13 PM
Awesome, thanks for pointing me in the right direction.

ataraxia
05-23-2008, 01:17 PM
Launchd provides native support for taking an action on mounting a filesystem via the "StartOnMount" key. See /System/Library/LaunchDaemons/com.apple.backupd-attach.plist for an example.

cwtnospam
05-23-2008, 01:54 PM
See /System/Library/LaunchDaemons/com.apple.backupd-attach.plist for an example.
Maybe that's in Leopard? I don't see it in Tiger. Supposedly the Leopard version of Lingon has more capabilities. Perhaps that's due to Leopard too.

ataraxia
05-27-2008, 10:44 AM
Maybe that's in Leopard? I don't see it in Tiger. Supposedly the Leopard version of Lingon has more capabilities. Perhaps that's due to Leopard too.

Yeah, it's Leopard-only. Launchd and friends are hugely more powerful in Leopard, and there are a lot more jobs controlled by it. The one I listed starts a Time Machine backup when you plug in your backup drive (actually, it starts Time Machine for every disk plugged in, and lets it figure out whether it's the right disk).