[TynesideLUG] newtar script

Ian Bruntlett ian.bruntlett at gmail.com
Sat Aug 7 13:54:14 UTC 2021


Here it is...

#!/usr/bin/env bash
# Ian Bruntlett, 20th April 2021 - 23rd July 2021
# newtar - file to list entries in a tar file newer than the date of a 2nd
file
# Based on this command: find ~/TECH-Manuals/ -newer ~/TECH-Manuals.tar.gz
# 2021-07-07 updated using advice from shellcheck
# 2021-07-23 ripped out $ERROR_CODE code, replaced it with call to file
command

function Usage
{
    cat <<END-OF-USAGE-MESSAGE
Usage: "$0" dir-of-source-files tar-file-that-backed-up-that-dir
Example: "$0" Desktop Desktop_02_April_2021.tar.gz
Note: Extra parameters passed on command line are passed on to find
END-OF-USAGE-MESSAGE
}

if [ $# -lt 2 ]; then
    Usage >&2
    echo Incorrect number of parameters - at least 2 expected, received $#
>&2
    exit 1
fi

if [ ! -d "$1" ]; then
    Usage >&2
    echo ERROR: Parameter 1 "$1" is not a directory >&2
    file "$1" >&2
    exit 1
fi

if [ ! -f "$2" ]; then
    Usage >&2
    echo ERROR: Parameter 2 "$2" is not a file  >&2
    file "$2" >&2
    exit 1
fi

STARTING_POINT=$1
TIME_REFERENCE=$2
shift
shift
find "$STARTING_POINT" -newer "$TIME_REFERENCE" "$@"

-- 
-- ACCU - Professionalism in programming - http://www.accu.org
-- My writing - https://sites.google.com/site/ianbruntlett/
-- Free Software page -
https://sites.google.com/site/ianbruntlett/home/free-software


More information about the Tyneside mailing list