LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 09-11-2008, 05:03 AM   #1
duryodhan
Senior Member
 
Registered: Oct 2006
Distribution: Slackware 12 Kernel 2.6.24 - probably upgraded by now
Posts: 1,054

Rep: Reputation: 46
Automate backup when a particular thumb drive is plugged in


Hi

I am mobile a lot (mobile == I use a number of different computers at different places) . I also use my pen drive to store/update my files/document as I find its much easier on me (I don't live in a country where net access is easy / painless).

What I want to achieve is :

* As soon as I plug in my pen drive to my home computer running slackware (the particular drive could be recognized by its uuid) , a particular folder is automatically copied by Slackware to my ~.

Any ideas on how I could do this ?

I think HAL/udev should be able to recognize the drive, and then I need to somehow call a script.

Any cool scripts/help would be great.

thanks
duryodhan
 
Old 09-11-2008, 06:56 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Yep, udev can run a script based on criteria you specify. See: http://www.reactivated.net/writing_u...l#external-run
 
Old 09-12-2008, 12:46 PM   #3
duryodhan
Senior Member
 
Registered: Oct 2006
Distribution: Slackware 12 Kernel 2.6.24 - probably upgraded by now
Posts: 1,054

Original Poster
Rep: Reputation: 46
ok .. am not at my Slack machine right now so can't test this but quick question

wouldn't this run before HAL has mounted the USB Key... and if I haven't mounted the key how can I copy something from it ?
 
Old 09-12-2008, 08:45 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
You could probably fork and return and then wait for some time and try the copy, as a thought.
 
Old 09-12-2008, 09:17 PM   #5
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.1
Posts: 2,367

Rep: Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843
You could try ivman/pmount to perform commands upon plugging in the thumb drive. I have no experience with either, but I *think* it should work. pmount just allows normal users to mount via HAL (ie a console version of the WM/DE-specific events), while ivman allows you to run commands when something is plugged in. I'm not sure if you can get away with JUST using ivman or if you need pmount as well -- not having any experience is not helping me here. However, a little research should help you figure that out. rworkman *seems* to know a bit about this based on past posts, but he may never see this. You might be able to search the forums for ivman for more help.

Good luck.
 
Old 09-13-2008, 04:03 AM   #6
duryodhan
Senior Member
 
Registered: Oct 2006
Distribution: Slackware 12 Kernel 2.6.24 - probably upgraded by now
Posts: 1,054

Original Poster
Rep: Reputation: 46
Thanks for your help all.


Quote:
You could probably fork and return and then wait for some time and try the copy, as a thought.
No offense Matir , but ewww Ughhh. ... :P


T3Slider - awesome .. it worked !

I am just posting what I did here ... someone else on searching can use it (as well as you guys can comment)

to start at console -
Quote:
lshal -m
Start monitoring devicelist:
-------------------------------------------------

and plug in your usb key.

you might get something like below
Quote:
-------------------------------------------------
14:33:14.801: usb_device_90c_1000_AA04012700007909 added
14:33:14.817: usb_device_90c_1000_AA04012700007909_usbraw added
14:33:14.850: usb_device_90c_1000_AA04012700007909_if0 added
14:33:19.827: usb_device_90c_1000_AA04012700007909_if0_scsi_host added
14:33:19.829: usb_device_90c_1000_AA04012700007909_if0_scsi_host_scsi_device_lun0 added
14:33:19.832: usb_device_90c_1000_AA04012700007909_if0_scsi_host_scsi_device_lun0_scsi_generic added
14:33:19.865: storage_serial_USB_FLASH_DISK_AA04012700007909_0_0 added
14:33:19.882: volume_uuid_D8C6_02E6 added
The key thing is volume_uuid_D8C6_02E6 .. we will use it later on (the value after uuid will be different for you)

Now go to slackbuilds.org and get the builds for ivman and pmount and install both.

Now

Quote:
vim ~/.ivman/IvmConfigActions.xml
And add lines like
Quote:
<ivm:Match name="hal.volume.uuid" value="D8C6-02E6">
<ivm:Option name="mount" value="true" />
<ivm:Option name="exec" value="cp $hal.volume.mount_point$/backup/* /targetbackuppath/ -u " />
<ivm:Option name="exec" value="pumount $hal.block.device$" />
</ivm:Match>
Note that the line <ivm:Option name="mount" value="true" > is also there at the top of the same file .. I commented that one out as I didn't want ivman to automount every USB drive thats plugged in. If you don't remove it there then don't add it here.

Also note how we matched the uuid noted down earlier .
I also automatically umount after the backup is done .. I am just more comfortable with some setup like this.


Now just add ivman to your startup .. for fluxbox (like me) , I added to the ~/.fluxbox/startup file. I didn't add it to rc.local cos I don't think above will work well if I run ivman as root.

Last edited by duryodhan; 09-13-2008 at 04:06 AM.
 
Old 09-13-2008, 10:19 AM   #7
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Much nicer solution, I must say. I'd never heard of ivman until this.
 
Old 09-13-2008, 11:13 AM   #8
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.1
Posts: 2,367

Rep: Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843
Quote:
Originally Posted by duryodhan
Now just add ivman to your startup .. for fluxbox (like me) , I added to the ~/.fluxbox/startup file. I didn't add it to rc.local cos I don't think above will work well if I run ivman as root.
If you want it to work in the terminal while logged in as a regular user (and I believe it should work when in X as well), you could add ivman to ~/.bash_profile (make sure to source .bash_profile or log out and back in for the changes to take effect). .bash_profile is only executed at a login shell, ie when you first log in as your user. .bashrc is executed at every interactive (non-login) shell, so ivman would be run multiple times (obviously not a good thing), so keep it in .bash_profile if you decide to do this. If you use another shell, obviously your solution may vary. I don't use runlevel 4, but that may be more problematic (or maybe not) since you log in graphically instead. Or you could just keep it in your fluxbox startup script.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically Purge Backup Files Off Thumb Drive JustinK101 Linux - Software 4 04-23-2007 05:46 PM
LXer: Speaking Unix, Part 6: Automate, automate, automate! LXer Syndicated Linux News 0 01-04-2007 09:54 AM
cannot automate rsync backup jahjr Linux - Server 6 12-21-2006 04:54 AM
USB thumb drive corrupts whenever plugged into Linux, but not windows. RHLinuxGUY Linux - Hardware 1 08-12-2006 08:00 PM
automate database backup Stormproof Linux - Networking 1 10-19-2004 03:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 11:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration