Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when a new SATA drive is inserted using Java under Linux?

Tags:

java

linux

sata

I am currently working on a project where I need to bulk import data into a Hadoop cluster. The data that needs to be imported into Hadoop resides on SATA disks. The data that needs to be imported are Encase forensics disks image (E01). I created an application that extract files from these images and import those files into Hadoop, this works fine but I need to start the process by hand.

I want to automate the process by hot-swapping the SATA drives and automatically start the extract process. I wrote my program in Java and it needs to be that way due to some external libraries I use to analyse the images. I searched the internet for a solution where Java is used to detect newly inserted drives but all I found where libraries that can detect usb drive or used udev rules to kick start the a process (I could use that but prefer a Java solution)

Does anyone know if something like what I have described exists? Or does anyone can point me into the right direction? It would be much appreciated!

Almost forgot...I use ubuntu 12.04 Server Edition as my operating system.

like image 320
Martijn Avatar asked May 26 '26 21:05

Martijn


1 Answers

udisks is a D-Bus API that provides information (including notifications) on media insertion and removal, and you could subscribe to the notifications using dbus-java.

Alternatively, you could have your Java application listen on a localhost socket and write a udev rule that sent the appropriate event information over the socket.

like image 150
chrylis -cautiouslyoptimistic- Avatar answered May 28 '26 09:05

chrylis -cautiouslyoptimistic-