Ubiquiti ERL script wanted to compare md5 values
-
So you can do...
thing you want to test || thing to do when it fails
-
So in your case:
md5sum -c /config/md5test.md5 || mail -s "You have a failure in your md5" [email protected]
-
If you needed to do the opposite where instead of failure you want to do something only on success you would use && instead of ||
-
You may need to install mailx, which supplies the mail command. It is very easy to work with for sending emails from a Linux system.
-
So you are implying that if the result is not ok for everything in the file that md5sum would execute the error condition if present?
I have not read the man file on md5sum at this point yet.
-
@JaredBusch said:
So you are implying that if the result is not ok for everything in the file that md5sum would execute the error condition if present?
Correct. But before you start emailing willy nilly, try this test example
md5sum -c /config/md5test.md5 || echo "Fail"
-
You can try with passing and failing md5sums and see if it actions the echo or not.
-
Yup, that does it.
jbusch@jared:~$ md5sum -c /config/md5test.md5 || echo "Fail" /root.dev/squashfs.img: OK md5sum: can't open '/root.dev/squashfs.': No such file or directory /root.dev/squashfs.: FAILED md5sum: WARNING: 1 of 2 computed checksums did NOT match Fail jbusch@jared:~$
-
Add this to clean it up...
md5sum -c /config/md5test.md5 2>/dev/null || echo "Fail"
-
looking at what i need to do to send an email. The documentation for ERL sucks as it is mostly community created and the package stuff changed with firmware 1.6.0
-
Also try it with good md5 sums to make sure it does nothing when they are successfully matched. Just to be sure.
-
@JaredBusch said:
looking at what i need to do to send an email. The documentation for ERL sucks as it is mostly community created and the package stuff changed with firmware 1.6.0
Oh shoot, forgot that it was ERL. Might not use the same mail command at all. That's a common syntax, but certainly not the only one.
-
@scottalanmiller said:
Also try it with good md5 sums to make sure it does nothing when they are successfully matched. Just to be sure.
I did.
jbusch@jared:~$ md5sum -c /config/md5test.md5 echo && "Successful test of MD5" || echo "Failed test of MD5" /root.dev/squashfs.img: OK /root.dev/squashfs.o: OK md5sum: echo: No such file or directory Failed test of MD5 jbusch@jared:~$ md5sum -c /config/md5test.md5 && echo "Successful test of MD5" || echo "Failed test of MD5" /root.dev/squashfs.img: OK /root.dev/squashfs.o: OK Successful test of MD5 jbusch@jared:~$
-
The first one "worked" because you put in three commands and the middle one had a typo so failed caused the third one to trigger. You didn't test what you think that you tested.
-
I did earlier then when doing further testing found it easier to use the typo instead of updating the .md5 file repeatedly. guess i could have made a second one for failure testing.. It is late and I am a bit lazy at this point.
-
@JaredBusch said:
I did earlier then when doing further testing found it easier to use the typo instead of updating the .md5 file repeatedly. guess i could have made a second one for failure testing.. It is late and I am a bit lazy at this point.
Only problem is that you are testing the failure of the echo command not of the md5sum in doing that.
-
I was making sure a success worked like i thought because i was thinking that writing it to a system log would be good even on success.
-
Oh no, I think you are right, that syntax should work.
-
Happy now?
jbusch@jared:~$ md5sum -c /config/bad.md5 && echo "Successful test of MD5" || echo "Failed test of MD5" /root.dev/squashfs.img: OK /root.dev/squashfs.o: FAILED md5sum: WARNING: 1 of 2 computed checksums did NOT match Failed test of MD5 jbusch@jared:~$ md5sum -c /config/good.md5 && echo "Successful test of MD5" || echo "Failed test of MD5" /root.dev/squashfs.img: OK /root.dev/squashfs.o: OK Successful test of MD5 jbusch@jared:~$
-
Yes better
Don't forget the 2>/dev/null so you only get the result message.