El 2/7/25 a las 4:31, Dale escribió:
Javier Martinez wrote: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 needsI tried to use commands that I use a lot already. The mountpoint command was a new one. Someone posted it on this list somewhere. I just had to get the commands to output less info instead of the usual bucket full I like. I have lsblk set to show a lot of info and that wouldn't be good in this script. I set it up as a alias. I'm not sure if scripts use the alias settings or not. I may rewrite a lot of this before it is over but so far, it works with a open and mounted device at least. If I could stop watching this TV series, I could unmount, close and then test the other part of the script. I'm kinda hooked. I like 'who done its'. Anyway, I'm looking into the [ and -f option. That looks promising. Thanks to all for the tips so far. I was expecting a lot more 'you did this completely wrong' tho. LOL Oh jeez!! I just did a 'man ['. Oh dear. O_O Dale :-) :-)
DEVICE=sda3 for dev in {0..15}; do if [[ -d "/sys/block/dm-$dev/slaves/$DEVICE" ]]; then echo "unlocked" fi doneThis checks if sda3 is unlocked checking the first 16 device mapper devices (0,1....15)
OpenPGP_0x57E64E0B7FC3BEDF.asc
Description: OpenPGP public key
OpenPGP_signature.asc
Description: OpenPGP digital signature