LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-01-2013, 12:26 PM   #1
ezekieldas
Member
 
Registered: Mar 2010
Posts: 122

Rep: Reputation: 16
idea: usb disk becomes available, do something


So I've been using this method to backup for some time: USB connection to an external SATA docking station, 1TB disk goes there. I then get on my system run dmesg, confirm the output below, mount /dev/sdd1 /opt.bk, then run a script I have that does all the backup magic.

I'd like to extend/improve this scheme by automating most, or possibly all of it. I'm wondering if anyone can tell me 1) is there a file in /proc that will tell me if this disk is available or not (I've looked and I'm not finding it) 2) does anyone have an example of a daemon or cron run job that watches for something in proc then acts on it?


Code:
usb 1-1.4: new high speed USB device using ehci_hcd and address 3
usb 1-1.4: configuration #1 chosen from 1 choice
Initializing USB Mass Storage driver...
scsi6 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 3
usbcore: registered new driver usb-storage
usb-storage: waiting for device to settle before scanning
USB Mass Storage support registered.
  Vendor: ST        Model: ST1000DM003-9YN1  Rev: 2.02
  Type:   Direct-Access                      ANSI SCSI revision: 04
SCSI device sdd: 1953525168 512-byte hdwr sectors (1000205 MB)
sdd: Write Protect is off
sdd: Mode Sense: 23 00 00 00
sdd: assuming drive cache: write through
SCSI device sdd: 1953525168 512-byte hdwr sectors (1000205 MB)
sdd: Write Protect is off
sdd: Mode Sense: 23 00 00 00
sdd: assuming drive cache: write through
 sdd: sdd1
sd 6:0:0:0: Attached scsi disk sdd
sd 6:0:0:0: Attached scsi generic sg4 type 0
usb-storage: device scan complete
 
Old 10-01-2013, 02:03 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,749

Rep: Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741
What I have in my backup script is to mount my USB drive, test if the backup directory now exists, run the backup, then umount.
The backup script runs from a cron job and adds start and end times to a log file in my home directory so I know how long its taking and whether it completed.
 
Old 10-01-2013, 03:23 PM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,133
Blog Entries: 2

Rep: Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836
If you want to start a your backup script once your disk becomes available have a look at udev scripts: http://reactivated.net/writing_udev_rules.html
 
Old 10-01-2013, 06:21 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,688

Rep: Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259
and if you use udev, you can tie the rule to a specific volumn name so that it backs up only when you plug in a device labeled for backup...
 
Old 10-02-2013, 10:01 AM   #5
ezekieldas
Member
 
Registered: Mar 2010
Posts: 122

Original Poster
Rep: Reputation: 16
I used this. It's a bit sloppy but seems to work fine.

Code:
cat /proc/bus/usb/devices  | grep "Driver=usb-storage" >/dev/null
if [ "$?" -ne "0" ]; then
  exit 1
fi

dmesg | tail -n 10  | grep sdd1 > /dev/null
if [ "$?" -ne "0" ]; then
  exit 1
fi
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Puzzled, no idea why I'm out of disk space valon24 Linux - Software 4 12-07-2010 09:47 PM
Is it safe / a good idea to disable disk spindown? MasterOfTheWind Linux - Hardware 1 09-01-2007 08:08 AM
Please help my idea about the virtual network disk:) Jedy Linux - General 1 12-06-2004 01:35 AM
Please help my idea about the virtual network disk:) Jedy Linux - Software 0 12-06-2004 12:34 AM
Silly idea about ram disk Half_Elf Linux - General 4 02-24-2003 12:02 AM


All times are GMT -5. The time now is 08:12 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration