jeffmakes / borg-consciousness

Script to alert administrator if a remote borg backup hasn't been made for a while
9 stars 3 forks source link

Grep on BusyBox #1

Open televisi opened 7 months ago

televisi commented 7 months ago

Hi

This is not an issue but more a discussion.

Great script! I wonder whether there is a way to update the script so that it can run from within the borgmatic docker instance - which most likely is using busybox.

When I tried to run the script from within borgmatic docker, it threw this error:

$ ./borg-consciousness.sh 
grep: unrecognized option: invert-match
BusyBox v1.36.1 (2023-07-27 17:12:24 UTC) multi-call binary.

Usage: grep [-HhnlLoqvsrRiwFE] [-m N] [-A|B|C N] { PATTERN | -e PATTERN... | -f FILE... } [FILE]...

Search for PATTERN in FILEs (or stdin)

        -H      Add 'filename:' prefix
        -h      Do not add 'filename:' prefix
        -n      Add 'line_no:' prefix
        -l      Show only names of files that match
        -L      Show only names of files that don't match
        -c      Show only count of matching lines
        -o      Show only the matching part of line
        -q      Quiet. Return 0 if PATTERN is found, 1 otherwise
        -v      Select non-matching lines
        -s      Suppress open and read errors
        -r      Recurse
        -R      Recurse and dereference symlinks
        -i      Ignore case
        -w      Match whole words only
        -x      Match whole lines only
        -F      PATTERN is a literal (not regexp)
        -E      PATTERN is an extended regexp
        -m N    Match up to N times per file
        -A N    Print N lines of trailing context
        -B N    Print N lines of leading context
        -C N    Same as '-A N -B N'
        -e PTRN Pattern to match
        -f FILE Read pattern from file

If that is not possible, all good, I'll find another Linux box to run the check.

Thanks

jeffmakes commented 7 months ago

Thanks! It looks like that BusyBox version of grep doesn't support options in --written-like-this format, only single letters. From the grep man page:

       -v, --invert-match
              Invert the sense of matching, to select non-matching lines.

You can replace --invert-match in the script with -v. If that fixes works ok, feel free to submit a PR.

Cheers

televisi commented 7 months ago

You can replace --invert-match in the script with -v. If that fixes works ok, feel free to submit a PR.

Thanks! I've done my first pull request; hopefully it works okay. I also added "BORG_RSH" variable too

jeffmakes commented 7 months ago

Great, thanks, merged. I tweaked it to always use -v, for compatibility everywhere.