LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-17-2015, 03:41 PM   #1
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Bash Script to Figure Out Which Partitions Are Encrypted?


I have two servers that have over 20 partitions and I'm trying to figure out which partitions are encrypted or not.

Instead of going thru each one manually with the blkid command, example: blkid /dev/sda

[root@example ~]# blkid /dev/sda2
/dev/sda2: UUID="rlW1d2-Bg0Z-tt33-UFbC-w0Xk-v64F-quyjJQ" TYPE="LVM2_member"

I want to use the power of Bash to do it.

I was thinking I would create a .txt (fdisk_output.txt) with all of the partitions and then have them loop thru and output the end results to a file, however I'm not sure if I'm on the right path or not:

Code:
#!/bin/bash 
for i in fdisk_output.txt 
do  
 blkid on i 
done

I'm not sure if my code is right, again the command that I want to loop thru is blkid against the various partitions and then output the results to a file.
 
Old 06-17-2015, 04:02 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,138

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
Simpler might be:

Code:
 blkid |grep '/dev/sd\w*[0-9]:'
 
Old 06-17-2015, 05:34 PM   #3
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
So I gave it a shot and came up with this

Code:
[user@foo tmp]$ sudo blkid | grep '/dev/sd\w*[0-9]:'
/dev/sda2: UUID="rlW1d2-Bg0Z-tt33-UFbC-w0Xk-v64F-quyjJQ" TYPE="LVM2_member"
/dev/sda1: UUID="1acb9f73-5f52-4522-8913-93fa93c0bb9a" TYPE="ext4"
I don't understand why the "w" character after the \ or escape character along with why searching the range from 0 to 9.

I change it to the following:

Code:
[user@foo tmp]$ sudo blkid | grep '/dev/sd\w*[a-z]:'
/dev/sdb: UUID="RM9TTp-WQuz-Rup8-HYfu-dcfT-IwNH-Df1wUt" TYPE="LVM2_member"
/dev/sdc: UUID="sLtjZW-5VWT-f3xy-rEI0-msuQ-hzak-OVvz1R" TYPE="LVM2_member"
/dev/sdd: UUID="YUFgcm-hcJE-Z0tk-zpXd-CmAx-fmdl-mpYPaU" TYPE="LVM2_member"
However it now skipped over sda along with not showing the partitions on /dev/sda (/dev/sda1 and /dev/sda2).
 
  


Reply

Tags
bash, blkid


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
LXer: Bash script to keep an encrypted text file of passwords LXer Syndicated Linux News 0 02-08-2015 06:21 AM
Recovering encrypted LVM partitions garden3 Linux - General 13 07-09-2013 02:17 PM
can one create a bash script to remove all partitions on harddrive via fdisk? chutsu Linux - General 5 10-06-2010 12:25 AM
ThumbPrint authentication and encrypted partitions? Mark_667 Ubuntu 0 05-31-2008 03:32 PM
Installing to encrypted partitions? compu73rg33k Ubuntu 2 11-03-2007 07:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration