How to get device from my HDD serial ?
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 ?
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.
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 :
I found this, but there may be better ways to do :
In order to read the serial number, you need to know the block device name, which puts you right back to the same problem.
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.
|All times are GMT -5. The time now is 03:06 PM.|