0

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
3
  • 6
    What have you tried? What have you thought of doing? Which commands have you considered? Are you constrained not to use sed or awk or Perl or Python, or are they options? It looks pretty straight-forward. Commented Nov 10, 2014 at 23:20
  • The only think I been looking at so far is BASH scripting because thats what i know best. But Python is an option and puppet. Im not to familiar with them thou. Commented Nov 11, 2014 at 2:15
  • So, how do you write a shell script that reads lines from a file, and splits them into fields that are interesting and those that are not? How do you find the last component of a pathname (the filename part)? It is very straight-forward — it could fit in the rest of this answer, but you wouldn't learn much if I spoon-fed you. Commented Nov 11, 2014 at 3:04

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

+1: Formally, it doesn't add the commas at the end of all but the last line, but somehow I suspect they probably aren't wanted anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.