diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-12-09 08:01:52 +0000 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-12-09 08:01:52 +0000 |
commit | 0e75a9915108f45e4d6a79aca6f39a65fc15a240 (patch) | |
tree | f091a14db9f657f3bf6d30c7e9998d95d8b868e0 /remind.sh | |
parent | 97d17a35c0aeec4ffea492867d8a79ec39c7684a (diff) |
regex parsing dates
Diffstat (limited to '')
-rwxr-xr-x | remind.sh | 41 |
1 files changed, 24 insertions, 17 deletions
@@ -12,44 +12,51 @@ # DESCRIPTION=$1 # echo $DESCRIPTION -if [[ $# < 1 || $# > 3 ]] ; then - echo "You need to give me three parameters. Expect DATE TIME DESCRIPTION." +echo "$# parameters given" + +if [[ $# != 2 ]] ; then + echo "You need to give me three parameters. Expect DATETIME (YYYYMMDDTHHMM) DESCRIPTION." exit 1 else - DATE="$1" - TIME="$2" - DESCRIPTION="$3" + DATETIME="$1" + DESCRIPTION="$2" fi -dateRegex='^[[:digit:]]{,2} [[:alpha:]]+ [[:digit:]]{4,4}$' -timeRegex='^[[:digit:]]{2,2}\:[[:digit:]]{2,2}$' +dateRegex='^([[:digit:]]{4,4})([[:digit:]]{2,2})([[:digit:]]{2,2})T([[:digit:]]{2,2})([[:digit:]]{2,2})$' -if [[ ! $DATE =~ $dateRegex ]] ; then - echo "Date must be of format: D[D] MONTH YYYY" +if [[ ! $DATETIME =~ $dateRegex ]] ; then + echo "Date must be of format: YYYYMMDDTHHMM" exit 1 fi -if [[ ! $TIME =~ $timeRegex ]] ; then - echo "Time must be of format: HH:MM" - exit 1 -fi +echo ${BASH_REMATCH[1]} +echo ${BASH_REMATCH[2]} +echo ${BASH_REMATCH[3]} + +year=${BASH_REMATCH[1]} +month=${BASH_REMATCH[2]} +day=${BASH_REMATCH[3]} + +# echo ${BASH_REMATCH[4]} + + DESC_LENGTH=$(expr length $DESCRIPTION) echo $DESC_LENGTH -if (($DESC_LENGTH > 2)) ; then - echo "Sorry, that is too long a description... Less than 2." +if (($DESC_LENGTH > 50)) ; then + echo "Sorry, that is too long a description... Less than 50 please." exit 1 fi if [[ -z "${TW_HOOK_REMIND_REMOTE_HOST}" ]] ; then - echo "There is not TW_HOOK_REMIND_REMOTE_HOST variable set." + echo "TW_HOOK_REMIND_REMOTE_HOST environment variable is not set. Set it to hostname of target machine." exit 1; else echo "TW_HOOK_REMIND_REMOTE_HOST set" fi -COMMAND="REM $DATE AT $TIME +15 *5 MSG $DESCRIPTION" +COMMAND="REM $DATETIME AT $TIME +15 *5 MSG $DESCRIPTION" ssh $TW_HOOK_REMIND_REMOTE_HOST ' cat ~/.reminders/work.rem |