Reputation: 25
I am trying to script out an encryption at rest tool and one part requires me to manually go and get mount point names.
I would like to script something to get these mount point names for me.
EX: mount point location and entry look like this "123412312312nkj12j3j12nj3n21nj311" I think is the disk serial number (If there is a way to check this please let me know)
cat /etc/fstab
/dev/mapper/123412312312nkj12j3j12nj3n21nj311 /ext4 defaults 1 2
/dev/mapper/123412312312nkj12j3j12nj3n21nj312 /ext4 defaults 1 2
/dev/mapper/123412312312nkj12j3j12nj3n21nj313 /ext4 defaults 1 2
/dev/mapper/123412312312nkj12j3j12nj3n21nj314 /ext4 defaults 1 2
/dev/mapper/123412312312nkj12j3j12nj3n21nj315 /ext4 defaults 1 2
/dev/mapper/123412312312nkj12j3j12nj3n21nj316 /ext4 defaults 1 2
/dev/mapper/123412312312nkj12j3j12nj3n21nj317 /ext4 defaults 1 2
after its parsed I would like the out put of the file to look just like this so i can then take the file and use it in my script.
123412312312nkj12j3j12nj3n21nj311,
123412312312nkj12j3j12nj3n21nj312,
123412312312nkj12j3j12nj3n21nj313,
123412312312nkj12j3j12nj3n21nj314,
123412312312nkj12j3j12nj3n21nj315,
123412312312nkj12j3j12nj3n21nj316,
123412312312nkj12j3j12nj3n21nj317
Upvotes: 0
Views: 2014
Reputation: 6692
I think you should use cut
command for this task, it will easily extract by dividing using delimiters such as space and /. I will give you an working example for you as following;
cut -d ' ' -f 1 /etc/fstab|cut -d'/' -f 4
This have two sections one will extract the /dev/mapper/123412312312nkj12j3j12nj3n21nj311
and last one will extract the 123412312312nkj12j3j12nj3n21nj311
.
This way you will get what you want from /etc/fstab
file.
Upvotes: 1