How to list ALL connected HDD devices in a script-friendly way? All - means both mounted and not mounted. Script-friendly - means something I can use for (u)mounting in my shell script with minimum grep'ing or sed'ing.
My task is to write some script which on startup will figure out where HDD is (if it's plugged in at all) and mount it. In my script I need some way to get list of available devices under /dev. What tool should I use in my script?
Here are options I considered:
fdisk -lgives much more information than I need - it is a bit hard to parse it's output in shell
parted -ldoes not list not mounted partitions and also outs a lot of extra information
cat /proc/partitionsbest output but does not list not mounted partitions
What tool fits my task the best way?
To clarify a bit where I'm coming from, here's my situation:
On some PC user will connect some HDD over USB or SATA. Then user restarts the PC. I know nothing about the HDD device, I can only assume that it has one partition with ext4 file system. The device could appear as /dev/sda or /dev/sdb. I have su access to the device and can add my script to /etc/rc.local or anywhere else but I have this access only before handing over the PC to the user.