ctdb-scripts: Avoid shellcheck warning SC2012 (ls for file list)
authorMartin Schwenke <martin@meltin.net>
Tue, 12 Jul 2016 20:53:21 +0000 (06:53 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 21 Jul 2016 00:24:27 +0000 (02:24 +0200)
SC2012: Use find instead of ls to better handle non-alphanumeric filenames.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/config/events.d/00.ctdb

index 3649ed001d69334cf5df54a85815c0c087c42a44..d60b9aa53c30bbf308c6862ef8f7db6782ec512e 100755 (executable)
@@ -93,9 +93,12 @@ EOF
            mv "$_db" "$_backup"
 
            # Now remove excess backups
-           ls -td "${_db}."*".corrupt" |
-           tail -n +$((${CTDB_MAX_CORRUPT_DB_BACKUPS:-10} + 1)) |
-           xargs rm -f
+           _max="${CTDB_MAX_CORRUPT_DB_BACKUPS:-10}"
+           _bdb="${_db##*/}" # basename
+           find "$_dir" -name "${_bdb}.*.corrupt" |
+                   sort -r |
+                   tail -n +$((_max + 1)) |
+                   xargs rm -f
        }
     done
 }