Jump to content

Running a script on USB stick insertion.


cooper

Recommended Posts

A friend of mine is converting an old laptop to a pictureframe PC. So far he's gotten Damn Small Linux installed on it and with a little help from yours truly it now boots straight into a user account, starts X and then kicks in the randomized image slideshow.

What he now wants to do is that when he inserts a USB stick into the machine, that the machine will automatically copy over all images from the stick onto the local filesystem, restart the image viewer so it can become aware of the newly added files, and possibly make the internal speaker beep once so he'll know the process is complete.

Now, I can easily script the doing of those tasks (the beep might be something to investigate, but an echo of ASCII 7 is prolly enough), but the tricky part is getting the script the actually run when the USB drive is inserted.

To make matters slightly worse, the Linux installation we painfully managed to install on the machine uses a Linux 2.4 kernel without udev or simliar hotplug stuff support best I can tell.

Any suggestions?

Link to comment
Share on other sites

You could have a cron job that looks for new entries in /dev every minuet or so, then do all the mounting and copying stuff when it finds a new entire (your script will probably have to assume the usb device inserted is at /dev/sda1 and that it's vfat).

The only down said to this is that you will have to have the USB device plugged in for upto a minuet for any thing to happen.

Link to comment
Share on other sites

No real need to do that, it's all over google:

http://www.scrounge.org/linux/cron.html

http://www.adminschoice.com/docs/crontab.htm

to make the script run once ever minuet you would set the cron file up like so:

0-59 * * * * root perl /root/mycopyingsctipt.pl

* * * * * should also work as you are telling it to run every minuet of every hour of every day of the month of every month of every day of the week, but 0-59 * * * * gives more clarity. (that was a nasty sentence to write lol, now time for some Zelda :D)

Link to comment
Share on other sites

As there is no udev, no new entries will appear on insertion of the stick. If the thing had udev, we could've used the discovery scripting stuff to start off the script we want to run.

We could just automatically mount /dev/sda1 every minute from cron, but I don't really like that to be honest. Additionally, some locking logic needs to be put in place in case the copying over of the images takes more than 1 minute to complete.

Nobody knows of a more targeted insertion detection mechanism?

Link to comment
Share on other sites

That's the thing. It _is_ ancient. Not so ancient that Linux 2.6 couldn't run on it, but this particular problem isn't serious enough to warrant a kernel replacement. So far his view is that it'll either get to work with 2.4, or he'll just live without the automagic copying over of the data.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...