ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Ubiquiti ERL script wanted to compare md5 values

    IT Discussion
    edgemax scripting ubiquiti md5 checksum bash
    2
    34
    8.9k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JaredBuschJ
      JaredBusch
      last edited by scottalanmiller

      I recently had one of the older model ERL die at a client site. I had a spare handy so I loaded a backup of their config on it and overnighted it.

      Their old one came back and the file system was corrupted. I suspect maybe the USB drive is dieing. There is a known low opinion of the quality of the USB in the first models (the ones in the plastic case with beveled corners).

      I have already flashed it and it is working fine, but I just came across a post on the UBNT community from one user stating that ever system that he has had failed due to a USB drive was showing MD5 differences in the system.

      He suggested running the following:

      md5sum /root.dev/squashfs.img /root.dev/squashfs.o
      #results in:
      dd15068cb6e3d7261a5a0877dc05aa5d  /root.dev/squashfs.img
      5d97f65401e0ae61969e29f66270b438  /root.dev/squashfs.o
      

      comparing that to the state md5 value shows they match for me right now.

      vi /root.dev/squashfs.img.md5
      dd15068cb6e3d7261a5a0877dc05aa5d
      

      and

      vi /root.dev/squashfs.o.md5
      5d97f65401e0ae61969e29f66270b438
      

      So now I want to setup a script to run this command and check the files and spit out a pass/fail result.z

      Linux administration is not my strong point. Linux shell scripting, even less so.

      1 Reply Last reply Reply Quote 1
      • JaredBuschJ
        JaredBusch
        last edited by

        I tried simply

        admin@aci:~$ md5sum -c /root.dev/squashfs.img.md5
        md5sum: WARNING: 1 of 1 computed checksums did NOT match
        admin@aci:~$
        
        1 Reply Last reply Reply Quote 0
        • scottalanmillerS
          scottalanmiller
          last edited by

          So you have the command that does the comparison. Looks like that's the right starting point. What more do you want it to do? Want it to actually state pass or fail?

          1 Reply Last reply Reply Quote 0
          • JaredBuschJ
            JaredBusch
            last edited by JaredBusch

            Creating my own md5 file I found the problem is that the current md5 does not contain the file path for the -c to test on..

            md5sum /root.dev/squashfs.img /root.dev/squashfs.o > /config/md5test.md5
            # results in
            vi /config/md5test.md5
            dd15068cb6e3d7261a5a0877dc05aa5d  /root.dev/squashfs.img
            5d97f65401e0ae61969e29f66270b438  /root.dev/squashfs.o
            #and now tests as
            md5sum -c /config/md5test.md5
            /root.dev/squashfs.img: OK
            /root.dev/squashfs.o: OK
            
            1 Reply Last reply Reply Quote 0
            • JaredBuschJ
              JaredBusch
              last edited by

              So now, how to integrate this or something to email me when they don't match.

              :sigh:
              too many thing I need to do at once..

              1 Reply Last reply Reply Quote 0
              • scottalanmillerS
                scottalanmiller
                last edited by

                So on failure is denoted by ||

                1 Reply Last reply Reply Quote 0
                • scottalanmillerS
                  scottalanmiller
                  last edited by

                  So you can do...

                  thing you want to test || thing to do when it fails
                  
                  1 Reply Last reply Reply Quote 0
                  • scottalanmillerS
                    scottalanmiller
                    last edited by

                    So in your case:

                    md5sum -c /config/md5test.md5 || mail -s "You have a failure in your md5" [email protected]
                    
                    1 Reply Last reply Reply Quote 0
                    • scottalanmillerS
                      scottalanmiller
                      last edited by

                      If you needed to do the opposite where instead of failure you want to do something only on success you would use && instead of ||

                      1 Reply Last reply Reply Quote 0
                      • scottalanmillerS
                        scottalanmiller
                        last edited by

                        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.

                        1 Reply Last reply Reply Quote 0
                        • JaredBuschJ
                          JaredBusch
                          last edited by

                          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.

                          scottalanmillerS 1 Reply Last reply Reply Quote 0
                          • scottalanmillerS
                            scottalanmiller @JaredBusch
                            last edited by scottalanmiller

                            @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"
                            
                            1 Reply Last reply Reply Quote 1
                            • scottalanmillerS
                              scottalanmiller
                              last edited by

                              You can try with passing and failing md5sums and see if it actions the echo or not.

                              1 Reply Last reply Reply Quote 0
                              • JaredBuschJ
                                JaredBusch
                                last edited by

                                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:~$
                                
                                1 Reply Last reply Reply Quote 0
                                • scottalanmillerS
                                  scottalanmiller
                                  last edited by

                                  Add this to clean it up...

                                  md5sum -c /config/md5test.md5 2>/dev/null || echo "Fail"
                                  
                                  1 Reply Last reply Reply Quote 0
                                  • JaredBuschJ
                                    JaredBusch
                                    last edited by

                                    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

                                    scottalanmillerS 1 Reply Last reply Reply Quote 0
                                    • scottalanmillerS
                                      scottalanmiller
                                      last edited by

                                      Also try it with good md5 sums to make sure it does nothing when they are successfully matched. Just to be sure.

                                      JaredBuschJ 1 Reply Last reply Reply Quote 0
                                      • scottalanmillerS
                                        scottalanmiller @JaredBusch
                                        last edited by

                                        @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.

                                        1 Reply Last reply Reply Quote 0
                                        • JaredBuschJ
                                          JaredBusch @scottalanmiller
                                          last edited by

                                          @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:~$
                                          
                                          1 Reply Last reply Reply Quote 0
                                          • scottalanmillerS
                                            scottalanmiller
                                            last edited by

                                            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.

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post