You are not logged in.
Determine if directories in variable 'directories' contain corrupted files
So here is my script thus far:
#!/bin/bash
#checkctl, JaydenDev 2022, MIT License
directories=("/boot" "/usr/lib" "/usr/lib32" "/usr/bin")
for group in "${directories[@]}"; do
echo Processing directory: $group
file $group/* | grep empty | grep -v ELF
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo Corrupted files in $group
else
echo No corrupted files in $group
fi
done
I have one example empty file in /usr/bin/ called rpmbuild. The script should detect this, but instead, here's the output:
Processing directory: /usr/lib
No corrupted files in /usr/lib
Processing directory: /usr/lib64
No corrupted files in /usr/lib64
Processing directory: /usr/lib32
No corrupted files in /usr/lib32
Processing directory: /usr/bin
No corrupted files in /usr/bin
Processing directory: /bin
No corrupted files in /bin
Processing directory: /sbin
No corrupted files in /sbin
Processing directory: /usr/sbin
No corrupted files in /usr/sbin
Last edited by JaydenDev (2022-07-23 17:10:15)
System Specs:
Intel Core i5-2400 Nvidia GTX 1050ti Logitech G402 Hyperion Fury (Mouse) BestBuy Essentials USB Keyboard
Software Specifications:
Desktop Environment: KDE Plasma Window Manager: KWin Operating System: Arch Linux (btw)
Offline
How do you equate empty with "corrupted"?
Also why all the variables and looping? And why loop through the same directories many times (as many of your directories in the array are symlinks to each other)?
If you just want to find empty files, use `find` with `-empty`:
find /usr/lib /usr/lib32 /usr/bin -type f -empty
But as for why yours fails - I suspect it's that you redirect the output of `file` to /dev/null, so you ignore all the results.
Last edited by Trilby (2022-07-23 17:01:10)
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
How do you equate empty with "corrupted"?
Also why all the variables and looping? And why loop through the same directories many times (as many of your directories in the array are symlinks to each other)?
If you just want to find empty files, use `find` with `-empty`:
find /usr/lib /usr/lib32 /usr/bin -type f -empty
But as for why yours fails - I suspect it's that you redirect the output of `file` to /dev/null, so you ignore all the results.
Removing the >&/dev/null causes the script to function. I assume if the binary or library is an empty file, then it's probably corrupted. Same goes for binaries. This checks system files, binaries, and libraries. OP updated with latest script.
Last edited by JaydenDev (2022-07-23 17:07:02)
System Specs:
Intel Core i5-2400 Nvidia GTX 1050ti Logitech G402 Hyperion Fury (Mouse) BestBuy Essentials USB Keyboard
Software Specifications:
Desktop Environment: KDE Plasma Window Manager: KWin Operating System: Arch Linux (btw)
Offline
Aside from the same question of why all the gymnastics rather than just using `find`, your new grep pipeline will do nothing. A file cant possibly be empty and be an ELF. And what do you think RESULT will get set to?
Last edited by Trilby (2022-07-23 17:53:17)
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
Aside from the same question of why all the gymnastics rather than just using `find`, your new grep pipeline will do nothing. A file cant possibly be empty and be an ELF. And what do you think RESULT will get set to?
some files contain 'empty' in their name.
System Specs:
Intel Core i5-2400 Nvidia GTX 1050ti Logitech G402 Hyperion Fury (Mouse) BestBuy Essentials USB Keyboard
Software Specifications:
Desktop Environment: KDE Plasma Window Manager: KWin Operating System: Arch Linux (btw)
Offline
some files contain 'empty' in their name.
And that doesn't suggest to you a problem in your design? Just the same filtering out ELF files from that makes no sense. Perhaps they are not empty, contain empty in their name, but are not ELF files. Or maybe some empty files contain ELF in their name! But I give up, you are ignoring most of the relevant questions.
Last edited by Trilby (2022-07-23 18:19:39)
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
JaydenDev wrote:some files contain 'empty' in their name.
And that doesn't suggest to you a problem in your design? Just the same filtering out ELF files from that makes no sense. Perhaps they are not empty, contain empty in their name, but are not ELF files. Or maybe some empty files contain ELF in their name! But I give up, you are ignoring most of the relevant questions.
I'm working on fixing the bad practices and methods. You asked why I used that method in the first place, I answered/=.
System Specs:
Intel Core i5-2400 Nvidia GTX 1050ti Logitech G402 Hyperion Fury (Mouse) BestBuy Essentials USB Keyboard
Software Specifications:
Desktop Environment: KDE Plasma Window Manager: KWin Operating System: Arch Linux (btw)
Offline
This is an xy-problem?
https://bbs.archlinux.org/viewtopic.php?id=278309
sudo env LC_ALL=C pacman -Qkk | grep -v ', 0 altered files
will tell you where you got issues.
Online
This is an xy-problem?
https://bbs.archlinux.org/viewtopic.php?id=278309sudo env LC_ALL=C pacman -Qkk | grep -v ', 0 altered files
will tell you where you got issues.
That's most definitely better than looking to see if files are empty. However that IS OS specific, specific to Arch.
System Specs:
Intel Core i5-2400 Nvidia GTX 1050ti Logitech G402 Hyperion Fury (Mouse) BestBuy Essentials USB Keyboard
Software Specifications:
Desktop Environment: KDE Plasma Window Manager: KWin Operating System: Arch Linux (btw)
Offline
However that IS OS specific, specific to Arch.
The thread doesn't imply a different requirement?
Online
However that IS OS specific, specific to Arch.
The thread doesn't imply a different requirement?
It's not required, I'll just have to rewrite the script if I every switch to another distro (I highly doubt I will, I use arch, I prefer arch, arch forever).
System Specs:
Intel Core i5-2400 Nvidia GTX 1050ti Logitech G402 Hyperion Fury (Mouse) BestBuy Essentials USB Keyboard
Software Specifications:
Desktop Environment: KDE Plasma Window Manager: KWin Operating System: Arch Linux (btw)
Offline
This is an xy-problem?
https://bbs.archlinux.org/viewtopic.php?id=278309sudo env LC_ALL=C pacman -Qkk | grep -v ', 0 altered files
will tell you where you got issues.
Just an add tip;)
Only show the warnings:
sudo env LC_ALL=C pacman -Qkk | grep -v ', 0 altered files' > /dev/null
or if you must;) see the backup file:
sudo env LC_ALL=C pacman -Qkk | grep -v ', 0 altered files' 2> /dev/null
Offline
Thanks very much everyone! Once I finish this up it'll be ready for its first stable release on GitHub, the AUR, and my repository.
System Specs:
Intel Core i5-2400 Nvidia GTX 1050ti Logitech G402 Hyperion Fury (Mouse) BestBuy Essentials USB Keyboard
Software Specifications:
Desktop Environment: KDE Plasma Window Manager: KWin Operating System: Arch Linux (btw)
Offline
Determine if directories in variable 'directories' contain corrupted files
How do you equate empty with "corrupted"?
…
And that doesn't suggest to you a problem in your design?
In order to know whether a file is "corrupted" you must be able to compare it to some reference.
For arch packages, that's the checksum in the package database - for some other distro packages it's gonna be something different and for everything else, you'll have to provide that reference.
Online
Don't randomly use sudo for commands that don't require root access.
And seriously, if you just want to find empty files, use find.
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
If you run pacman -Qkk w/o root permissions you'll be unable to test a bunch of files and get warnings for that.
Online
True, but most - if not all - of the files in that category would quite commonly be edited and not match the package checksum anyways.
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
Alright so obviously I have a lot to work on with my bash scripting skills. So much so, some of them have a chance of being dangerous (not sure, but with the amount of bad practices in use its entirely possible). I will leave the development of this software here, and do some more practice.
System Specs:
Intel Core i5-2400 Nvidia GTX 1050ti Logitech G402 Hyperion Fury (Mouse) BestBuy Essentials USB Keyboard
Software Specifications:
Desktop Environment: KDE Plasma Window Manager: KWin Operating System: Arch Linux (btw)
Offline