Skip to content

Commit

Permalink
Add error checking of archive-log timestamp parameters
Browse files Browse the repository at this point in the history
Check if the format of the timestamp command-line parameters matches
the required format.  If not, exit with an error message.  This will
prevent archive-log from creating an archived log file with a corrupt
filename or in a directory with a corrupt name.

Also simplified the code that gets the current century.
  • Loading branch information
Daniel Thayer committed Jan 13, 2017
1 parent f6d4515 commit d5475e9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions bin/archive-log
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,20 @@ to=$4
terminating=$5
writer=$6

century=`date +%Y | sed 's/..$//'`
# Verify if the given timestamp is in the correct format (YY-MM-DD_HH.MM.SS).
check_timestamp() {
res=`echo $2 | sed 's/[0-9][0-9]-[0-1][0-9]-[0-3][0-9]_[0-2][0-9][.][0-5][0-9][.][0-5][0-9]/VALID/'`
if [ "$res" != "VALID" ]; then
echo "archive-log: $1 time must be in format YY-MM-DD_HH.MM.SS: $2" >&2
exit 1
fi
}

check_timestamp start $from
check_timestamp end $to

# Convert timestamps to the format YYYY-MM-DD-HH-MM-SS
# Convert timestamp format from YY-MM-DD_HH.MM.SS to YYYY-MM-DD-HH-MM-SS
century=`date +%C`
from=`echo $century$from | sed 's/[_.]/-/g'`
to=`echo $century$to | sed 's/[_.]/-/g'`

Expand Down

0 comments on commit d5475e9

Please sign in to comment.