Software lies, /sys lies less (but rootkits could make it lie too).

Have you thought in parse /sys/block looking for dm* directories, and after that check if subdir slave is the one you want??

I want mean:

In /sys/block you have all block devices recognized in your system. You know that cryptsetup uses device mapper, so that if the volume is unlocked it has one dm device created (dm-0, dm-1)

you could check all dm devices there (they are "unlocked" even if they does not use dmcrypt...) and check if the /sys/block/dm-?/slaves/whateverpartition exists and whateverpartition is the one are you interested.

Probably your script will be a bit faster since you avoid exec commands, more trusted since you use kernel facility, and finally usually lsblk and friends (as ps or top with /proc) uses this information to their needs




El 2/7/25 a las 3:33, Dale escribió:
Eli Schwartz wrote:
On 7/1/25 7:50 PM, Dale wrote:
It took me a while to figure out how important spaces are and where they
have to be for things to work around the ifs.  Put a space in the wrong
place, or leave one out where there should be one, it pukes on your
keyboard.
Spaces separate "words" in a command. And something that sometimes
surprises people is that in shell scripts, brackets, that is, [ and [[
are both "commands". They take a series of arguments.

For example,

if [ "$?" -eq "0" ] ; then

The "if" must be followed by a command to test its value. [ is a
command, and takes four arguments:

argument 1: $?
argument 2: -eq
argument 3: 0
argument 4: ]


The "]" argument tells it to stop reading arguments.:)

Using ; is equivalent to adding a newline, but prettier. It is legal to
do this:


if [ "$?" -eq "0" ];then

It just looks really ugly.:) :) :) Spaces help you read.



-- Eli Schwartz


Now I read somewhere that the [ and ] is a command but forgot that. That explains a lot.  I was looking at books and such and just sort of did the same as they did for some of it.  The hard part was figuring out if something was open or not and how to detect it and if something was mounted or not.  Another thing I learned, what works on the command line doesn't always work in a script.  Opposite is true too.

I also moved the "else" over from your other post.

Thanks.

Dale

:-)  :-)

P. S.  By the time I learn enough to be dangerous, I'll die of old age.  :/

Attachment: OpenPGP_0x57E64E0B7FC3BEDF.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to