diff --git a/README.md b/README.md index 0e008d8..a2e0131 100644 --- a/README.md +++ b/README.md @@ -3,28 +3,27 @@ `run_old_files_delete.sh` is a related script intended to be used for making unattended script calls into `old_files_delete.sh` (*e.g.*, running cron jobs). -## [](https://github.com/richbl/a-bash-template)Developed with a Bash Template (BaT) +## [Developed with a Bash Template (BaT)](https://github.com/richbl/a-bash-template)[](https://github.com/richbl/a-bash-template) -**Old-Files-Delete** uses a bash template (BaT) called **[A-Bash-Template](https://github.com/richbl/a-bash-template)** designed to make script development and command line argument management more robust, easier to implement, and easier to maintain. Here are a few of those features: +**Old-Files-Delete** uses a Bash shell template (BaT) called **[A-Bash-Template](https://github.com/richbl/a-bash-template)** designed to make script development and command line argument management more robust, easier to implement, and easier to maintain. Here are a few of those features: -- Dependencies checker: a routine that checks all external program dependencies (*e.g.*, [sshpass](http://linux.die.net/man/1/sshpass) and [jq](https://stedolan.github.io/jq/)) +- Dependencies checker: a routine that checks all external program dependencies (*e.g.*, [jq](https://stedolan.github.io/jq/)) - Arguments and script details--such as script description and syntax--are stored in the [JSON](http://www.json.org/) file format (*i.e.*, `config.json`) - JSON queries (using [jq](https://stedolan.github.io/jq/)) handled through wrapper functions - A script banner function automates banner generation, reading directly from `config.json` -- Command line arguments are parsed and tested for completeness using both short and long-format argument syntax (*e.g.*, `-u|--username`) +- Command line arguments are parsed and tested for completeness using both short and long-format argument syntax (*e.g.*, `-f|--font`) - Optional command line arguments are permissible and managed through the JSON configuration file -- Template functions organized into libraries to minimize code footprint in the main script +- Template functions organized into libraries (see the [Bash-Lib](https://github.com/richbl/bash-lib) project for details) to minimize code footprint in the main script For more details about using a bash template, [check out the BaT sources here](https://github.com/richbl/a-bash-template). ## Requirements - - An operational [bash](https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29) environment (bash 4.3.2 used during development) - - One additional external program: - + [jq](https://stedolan.github.io/jq/), for parsing the `config.json` file - -While this package was written and tested under Linux (Ubuntu 15.10), there should be no reason why this won't work under other Unix-like operating systems. +- An operational [Bash](https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29) environment (Bash 5.1.8 used during development) +- One additional external program: + - [jq](https://stedolan.github.io/jq/), for parsing the `config.json` file +While this package was initially written and tested under Linux (Ubuntu 21.10), there should be no reason why this won't work under other shells or Unix-like operating systems that support the `gsettings` application. ## Basic Usage **Old-Files-Delete** is run through a command line interface, so all of the command options are made available there. @@ -35,7 +34,7 @@ Here's the default response when running `old_files_delete.sh` with no arguments | | A bash script to recursively delete files older than (n) days - | 0.1.0 + | 1.1.0 | | Usage: | old_files_delete.sh -d directory -n days_ago @@ -55,7 +54,7 @@ When arguments are correctly passed, the script provides feedback on the success | | A bash script to delete files older than (n) days - | 0.1.0 + | 1.1.0 | | Usage: | old_files_delete.sh -d directory -n days_ago @@ -79,7 +78,7 @@ The example below represents my own cron job set to run nightly at 00:15 on my R As configured, I no longer have to worry about motion-captured image files (jpg and avi files) getting generated over time, and eventually consuming available disk space on my IoT device. -## A Note on Cloning: This Project Uses Git Submodules +## >> A Note on Cloning: This Project Uses Git Submodules This project uses a Git [submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules) project, specifically the `bash-lib` folder to keep project libraries up-to-date without manual intervention. diff --git a/bash-lib b/bash-lib index 136d70d..5ecefd2 160000 --- a/bash-lib +++ b/bash-lib @@ -1 +1 @@ -Subproject commit 136d70d912b913857c5d3a2e75e9a15c091fab06 +Subproject commit 5ecefd2342e4e913ee772ee0b82db34d030fbae8 diff --git a/old_files_delete.sh b/old_files_delete.sh index 3f7b6c0..fa266ae 100755 --- a/old_files_delete.sh +++ b/old_files_delete.sh @@ -4,16 +4,16 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin # ----------------------------------------------------------------------------- # Copyright (C) Business Learning Incorporated (businesslearninginc.com) # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License at +# for more details. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License at for -# more details. # ----------------------------------------------------------------------------- # # A bash script to recursively delete files older than (n) days @@ -30,33 +30,46 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin # --side-effect(s): older files deleted # +# +# NOTE: +# The string '[user-config]' is an indication that some user configuration +# may be needed to customize this script +# +# FOR MORE INFORMATION: +# This script was written using the BaT template. To learn more, refer to +# the A-Bash-Template project (https://github.com/richbl/a-bash-template) +# + # ----------------------------------------------------------------------------- -# script declarations +# script library sources and declarations # -shopt -s extglob -EXEC_DIR="$(dirname "$0")" -# shellcheck source=bash-lib/args +EXEC_DIR="$(dirname "$(readlink -f "$0")")" +source "${EXEC_DIR}/bash-lib/general" source "${EXEC_DIR}/bash-lib/args" +# [user-config] set any external program dependencies here declare -a REQ_PROGRAMS=('jq') # ----------------------------------------------------------------------------- # perform script configuration, arguments parsing, and validation # - check_program_dependencies "${REQ_PROGRAMS[@]}" display_banner scan_for_args "$@" check_for_args_completeness +# ----------------------------------------------------------------------------- +# [user-config] +# Any code from this point on is custom code, using the sevices provided +# through this BaT (https://github.com/richbl/a-bash-template) template + # ----------------------------------------------------------------------------- # perform old file delete # echo "Deleting old files..." echo -find $(get_config_arg_value directory) -mtime +$(get_config_arg_value 'days ago') -type f -delete -if [ $? -ne 0 ]; then +if ! find "$(get_config_arg_value directory)" -mtime +"$(get_config_arg_value 'days ago')" -type f -delete; then echo "Error: file delete did not complete." quit else diff --git a/run_old_files_delete.sh b/run_old_files_delete.sh index ee02174..aebb02c 100755 --- a/run_old_files_delete.sh +++ b/run_old_files_delete.sh @@ -4,32 +4,27 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin # ----------------------------------------------------------------------------- # Copyright (C) Business Learning Incorporated (businesslearninginc.com) # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License at for -# more details. +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License at +# for more details. +# # ----------------------------------------------------------------------------- # # A bash script front-end to call old_files_delete.sh # -# version: 0.1.0 -# # requirements: -# # --access to old_files_delete.sh # # inputs: -# # --None (runs with no inputs) # # outputs: -# # --None (side effect is the completion of the called script) #