How do I detect that a jump drive is mounted?
Fred Roller
froller at tnclimited.com
Sat Aug 29 03:49:00 UTC 2009
On Fri, 2009-08-28 at 20:23 -0700, Knute Johnson wrote:
> Fred Roller wrote:
> > On Fri, 2009-08-28 at 15:18 -0700, Knute Johnson wrote:
> >> I've got a jump drive that I use to back up some files at night. Is
> >> there a simple way in a script that I can check to see that the drive is
> >> mounted?
> >>
> >> Thanks,
> >>
> >> --
> >>
> >> Knute Johnson
> >>
> >>
> >
> > A better option may be to have the script run your backup when the jump
> > drive is inserted. Found this article on someone doing similar for
> > their back up scenario.
> >
> > http://ubuntuforums.org/showthread.php?t=904522
> >
> > In the first suggestion using the "rules" I personallyhad some success
> > but was trying things with vmware at the time.
> >
> > the second suggestion, the one the OP used, seems to be the best fit for
> > your situation. You could also search
> > "ubuntu run script on usb insert"
> > which yielded a number of options. Hope it's helpful.
>
> Thanks for the response. I'm leaving the jump drive plugged in all the
> time so that's not a great option for me. Secondly I'm running the
> server version so it doesn't automatically mount jump drives. On second
> thought, how does that automatic mounting work? Is there a program I
> could install that would automount it?
>
> --
>
> Knute Johnson
>
>
Generally speaking, udev handles the auto mounting I think. You also
have the option to add your own rules, read (from command line):
less /etc/udev/rules.d/README
and
man udev
man udevadm
man udevd
I did something similar about a year ago (which is why I can't just spit
out a solution for you ;)). At any rate, the solution detected the usb
drive on insertion->mounted to a specific location->ran a backup
script->unmounted the drive->beeped when completed. The usb detection
activated on specifically on the drive label.
The only issue I couldn't get over was the shadow icon on the desktop
that were left behind. (I was using a GUI for the user). Since you are
not using a GUI this would not matter.
My script was nothing more than the commands I would use if running
manually with the && (double and sign) after each to ensure successful
completion before moving on.
Others here that know a heck of lot more than I do can probably help
flesh out the details. I remember it not being hard at all once I
understood the udev rules.
Fred
More information about the ubuntu-users
mailing list