aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-12-09 08:01:52 +0000
committerMatthew Lemon <lemon@matthewlemon.com>2020-12-09 08:01:52 +0000
commit0e75a9915108f45e4d6a79aca6f39a65fc15a240 (patch)
treef091a14db9f657f3bf6d30c7e9998d95d8b868e0
parent97d17a35c0aeec4ffea492867d8a79ec39c7684a (diff)
regex parsing dates
-rwxr-xr-xremind.sh41
1 files changed, 24 insertions, 17 deletions
diff --git a/remind.sh b/remind.sh
index b543652..d9ae74d 100755
--- a/remind.sh
+++ b/remind.sh
@@ -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