diff --git a/checkFileCount/5 b/checkFileCount/5 new file mode 100644 index 0000000..e69de29 diff --git a/checkFileCount/arg[2] b/checkFileCount/arg[2] new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/checkFileCount/arg[2] @@ -0,0 +1 @@ +1 diff --git a/checkFileCount/checkFileCount.fish b/checkFileCount/checkFileCount.fish new file mode 100755 index 0000000..dced2c5 --- /dev/null +++ b/checkFileCount/checkFileCount.fish @@ -0,0 +1,21 @@ +#!/usr/bin/env fish +# $argv[1] = directory you want to scan +# $argv[2] = minimum amount of files you want to keep + +set files (count (./golf $argv[1])) + +if test $files -gt $argv[2] + set fileList (./golf $argv[1]) + set oldestDate (stat -c %W "$argv[1]/$fileList[1]") + set fileIndex = 1 + + for i in (seq $files) + set dateCreated (stat -c %W "$argv[1]/$fileList[$i]") + if test $dateCreated -gt $oldestDate + set oldestDate $dateCreated + set fileIndex $i + end + end + + rm "$argv[1]/$fileList[$fileIndex]" +end diff --git a/checkFileCount/count.mockup b/checkFileCount/count.mockup new file mode 100644 index 0000000..4b10a33 --- /dev/null +++ b/checkFileCount/count.mockup @@ -0,0 +1,19 @@ +files = number of files in arg[1] # likely going to be named sql-backup + +if files > arg[2] # specified number of files to keep + + fileList = array of files in arg[1] + oldestDate = fileList[1] date created # doesn't matter which file + fileIndex = 1 # or 0 but fish just uses index 1 for the beginning of an array + + for i = 1; i > files; i++ + + dateCreated = fileList[i] date created + if oldestDate < dateCreated + oldestDate = dateCreated + fileIndex = i + end + end + + delete fileList[fileIndex] +end diff --git a/checkFileCount/golf b/checkFileCount/golf new file mode 100755 index 0000000..ad82885 Binary files /dev/null and b/checkFileCount/golf differ diff --git a/checkFileCount/test/1 b/checkFileCount/test/1 new file mode 100644 index 0000000..e69de29 diff --git a/checkFileCount/test/2 b/checkFileCount/test/2 new file mode 100644 index 0000000..e69de29 diff --git a/checkFileCount/test/3 b/checkFileCount/test/3 new file mode 100644 index 0000000..e69de29 diff --git a/checkFileCount/test/4 b/checkFileCount/test/4 new file mode 100644 index 0000000..e69de29