[Bash] MD5 Checks with Script.
Hi.
I'm triyng to make a Bash Script that checks (recursively) the MD5 from all the files in a certain directory and compare them against some other check that should be already done and saved in a file. I've reached to the point where i have the MD5 from the file and the MD5 that the script saved in a file the last time it runs. But, for some reason, when i compare them, the script always tell me that the MD5 change! Here is the part of the script that make the comparision: Code:
for Archivo in $Archivos; do Code:
#!/bin/bash Thanks in advance. Bye! |
Can we see an example of the contents of your log file, the one designated by $LogMasNuevo? I think it might be key to figuring out your problem, because I don't see anything offhand to explain why it doesn't work (at least in the section you gave first, I haven't thoroughly looked at the full script yet).
In the meantime, I'd like to make a few general suggestions about your script. 1) $(..) is highly recommended over `..` for embedded commands. 2) Code:
FileMD5=`echo ${Arch%% *}` Code:
FileMD5=${Arch%% *} 3) Code:
FileMD5=`echo $FileMD5 | sed 's/ //g'` Code:
FileMD5=${FileMD5// } But as I read the code, these variables should never be anything but straight strings, so this step isn't really necessary. There are, however, many other places you could use parameter substitution in your script. You can use it instead of the dirname and basename commands, for example. 4) Code:
if [ ! $(echo "$HistoriaLogs" | grep -E "^[0-9]+$") ] Code:
if [[ ! "$HistoriaLogs" =~ ^[0-9]+$ ]] In fact, I personally recommend using the extended test construct all the time. It can avoid a lot of hassles. :) |
you can do md5sum on all files
Code:
md5sum $Archivo/* 2>/dev/null |
David, i've made the changes you mark me in my script. The articles are interesting.
An Example of the LOG File generated by the Script when i run it in the "/sysx/src/Nagios/Plugins/HP/" Directory: Code:
f7407b3f175b3c566d0c89eeacae6571 /sysx/src/Nagios/Plugins/HP/check_hp-2.5.tar.gz |
A-ha. It appears to be a simple mistake, easy to overlook:
Code:
# żAre the MD5's different? A useful way to help debug a script is to add "-x" to the first line (#!/bin/bash -x), which makes it display all the behind the scenes substitutions. You can also turn it on and off inside the script with "set -x" and "set +x". There's also a "-v" option for even more verbose output. By the way, it looks like my previous tip #4 above doesn't work here after all. The regex won't match single lines, and compares the input string as a whole. It would require a complex work-around to get it working right. |
Hi!
I noticed the problem the other day and i today i've finished the script. Here it is... (Readme & Comments in Spanish). Code:
#!/bin/bash Bye. |
All times are GMT -5. The time now is 01:43 PM. |