LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 09-28-2011, 09:52 AM   #1
pmorin
Member
 
Registered: Jun 2011
Posts: 40

Rep: Reputation: Disabled
Question How to get device from my HDD serial ?


Hi !

I'm creating a script that will make a backup of my server files directly by plugging my external HDD on my server.

I found out how to run a script when I plug my HDD on my server (here) and now I want to do this with my scripts :
1. mount all the partitions of the external HDD
2. make a backup (that is already OK)
3. unmount all the partitions of the external HDD (I just need to run some "umount" to do this, so that should not be a problem)
4. eject the external HDD (safely remove hardware) : I found a script to do this here, but I need to get the device

So I have problems for points 1. and 4. :
1. I can't use "mount -a" : I don't know why, but it's not working
4. I don't have the device name (in my case, now, it's /dev/sdc, but it could be something else)

In both cases, I need to find what is the device name of my external HDD. I know the name of the partitions of the HDD, and its serial.
How can I find the device from the HDD serial ?

I have some leads, like using "sudo lshw -short", but I'm not an expert of regex (to parse its output).

Can somebody help me, please ?

Thanks !
Pierre
 
Old 09-28-2011, 02:07 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
The mount command can only mount partitions if run with root privileges.
UUIDs and labels are good for unambiguously identifying partitions.
See a LQ thread on the subject for a good jumping off point on the subject.
--- rod.
 
Old 09-29-2011, 02:52 AM   #3
pmorin
Member
 
Registered: Jun 2011
Posts: 40

Original Poster
Rep: Reputation: Disabled
Thank you for your help.

For root privileges, that's not a problem.
For UUIDs of partitions, that could be good, but I would prefer using HDD serial : I need the device name of the HDD, not its partitions ones.

But you gave me an idea : I could try adding the partitions to fstab.

Anyway, I found another method to get the device name of my HDD : using "fdisk -l" with "grep" and ["sed"/"awk"/something else that use regex].
I know that my HDD has a capacity of 2000398934016 Bytes, so I could us this :
Quote:
sudo fdisk -l | grep -Hn "2000398934016" | sed -r 'XXXXX'
I don't know what to replace "XXXXX" with. Can anybody help, please ?

Thanks !
 
Old 09-29-2011, 02:59 AM   #4
pmorin
Member
 
Registered: Jun 2011
Posts: 40

Original Poster
Rep: Reputation: Disabled
I found this, but there may be better ways to do :
Quote:
sudo fdisk -l | grep "2000398934016" | sed -r 's/:.*//' | sed -r 's/.*\s//'
 
Old 09-29-2011, 10:02 AM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
In order to read the serial number, you need to know the block device name, which puts you right back to the same problem.
--- rod.
 
Old 09-29-2011, 10:06 AM   #6
pmorin
Member
 
Registered: Jun 2011
Posts: 40

Original Poster
Rep: Reputation: Disabled
Thank you for your response.

I don't need to read the serial number : I already have it and it wouldn't change, so I can "hard-code" it directly in my script.
 
  


Reply

Tags
device, serial, usb


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
Is it possible to access an IrDA device as a serial device such as /dev/ttyUSB0? cricketlong Linux - Hardware 1 05-24-2011 03:11 PM
Hdd serial no rajiv.patil82 Linux - Server 3 04-06-2010 09:34 AM
Serial input device using usb-serial connector slackiz Linux - Hardware 4 01-12-2009 05:04 AM
USB device as serial device BlackHatRob Linux - Hardware 1 06-08-2006 07:09 PM
Reading the HDD serial number DJFauß Linux - Hardware 1 06-06-2002 01:27 PM


All times are GMT -5. The time now is 07:18 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration