Koozali.org: home of the SME Server

USB: How to autorun script

clgravel

USB: How to autorun script
« on: August 17, 2004, 05:03:15 PM »
I have installed SME 6.0 w/ raid to provide failover support. In addition to this I am trying to create a means for offsite backups through an external USB hard drive. When connected, SME detects the hard drive correctly and loads the usb-storage module, and I have written a script to mount the drive, perform a backup, unmount the drive, and send an email to a user when the backup is finished. What I am trying to do is to get this script to run automatically when the drive is plugged in so the user does not need to do anything when the drive is plugged in. Then when they get the email they know the task is complete and they can remove the drive and take it off site.

I have read documentation about hotplug and instructions for having scripts automatically run. For example, I have added my script to the /etc/hotplug/usb directory, and I have added an entry in usb.handlemap for this particular device:

backup_script  0x0003  0x0d49  0x7000  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x0

I was wondering if anyone has utilized usb connection scripts for items such as cameras, memory sticks, or external hard drives and if they needed to change anything in the hotplug.agent

Any help would be greatly appreciated.

Offline mophilly

  • *
  • 384
  • +0/-0
    • Mophilly
re: USB: How to autorun script
« Reply #1 on: August 17, 2004, 09:11:39 PM »
I have not done such a thing, but perhaps a cron script would be useful. It wouldn't occur when the device is loaded per se but it could be run fairly often.

I suppose there is something down deep in the os that could be modified, but I am not the one to offer advise on that.

hth,
- Mark

clgravel

USB: How to autorun script
« Reply #2 on: August 17, 2004, 09:25:24 PM »
I have considered a cron job but a couple of issues come up. If I run the job at a specific time, and the drive is not attached or is attached shortly after the specified time, the job won't be completed. If the job is run too often and the drive is not removed soon enough after the backup is complete, then it could perform an additional backup.

If I can automount the external drive when it is plugged in then I could make the script test to see if the drive is mounted and when it is, run the backup. Then at the end of the script unmount the drive so the cron job no longer sees the drive as mounted. Without moving from the original question of getting the hotplug script to work, how would I detect if an instance of a script is already running so that it doesn't start another instance of it?

Thanks in advance any valuable insight.

Offline mophilly

  • *
  • 384
  • +0/-0
    • Mophilly
USB: How to autorun script
« Reply #3 on: August 20, 2004, 01:32:33 AM »
Well, as I said I haven't attempted this. Clearly, getting a hook into the auto-mount is the way to go. If you post a url to the "hot-plug" instructions and related stuff, I will look it over to see if I can add something useful.
- Mark

BobWilliams

USB: How to autorun script
« Reply #4 on: October 13, 2004, 03:42:13 PM »
Has any progress been made on this topic? I'm trying to do the same thing. clgravel could you share your script for us to try?

Bob...

BobWilliams

USB: How to autorun script
« Reply #5 on: October 13, 2004, 05:23:20 PM »
I found this How to with the answer to the USB Hard Drive auto-mount problem. Works for me on SME 6.0.1.  

Code: [Select]
http://mirror.contribs.org/smeserver/contribs/mblotwijk/HowToGuides/AddExtraHardDisk.htm

Refer to Step 5 for the solution.

thanks Michiel...

Bob...