cfgfoo

git clone https://orangeshoelaces.net/git/cfgfoo.git

8e317ac6b0c7a91a654dc02baff5e8447fd33986

Author: Vasilii Kolobkov on 12/22/2018

Committer: Vasilii Kolobkov on 12/22/2018

Schedule tasks with cron

Stats

aliases                           |  3 +-
steps/acme-client/schedcrtrefresh | 15 --------
steps/crontab/add                 | 12 ++++++
3 files changed, 14 insertions(+), 16 deletions(-)

Patch

diff --git a/aliases b/aliases
index 00ea864..136f186 100644
--- a/aliases
+++ b/aliases
@@ -2,7 +2,8 @@
 alias cfgfoo="${CFGFOOPATH}/cfgfoo"
 
 alias acmeclient_reqcrt1="cfgfoo ${CFGFOOPATH}/steps/acme-client/reqcrt1 "
-alias acmeclient_schedcrtrefresh="cfgfoo ${CFGFOOPATH}/steps/acme-client/schedcrtrefresh "
+
+alias crontab_add="cfgfoo ${CFGFOOPATH}/steps/crontab/add "
 
 alias edit_appendfln="cfgfoo ${CFGFOOPATH}/steps/edit/appendfln -s "
 alias edit_overrideln="cfgfoo ${CFGFOOPATH}/steps/edit/overrideln -s "
diff --git a/steps/acme-client/schedcrtrefresh b/steps/acme-client/schedcrtrefresh
deleted file mode 100644
index e582794..0000000
--- a/steps/acme-client/schedcrtrefresh
+++ /dev/null
@@ -1,15 +0,0 @@
-step_taken() {
-	crontab -l | grep -q "acme-client.\{1,\}$1"
-}
-
-# 'crontab -' is not in POSIX, nor is 'jot'
-take_step() {
-	{
-		printf '%d\t' "$(jot -r 1 0 59)"
-		printf '%d\t' "$(jot -r 1 - 23)"
-		printf '*\t'
-		printf '*\t'
-		printf '%s\t' "$(jot -r 1 1 7)"
-		printf "acme-client '$1'\n"
-	} | crontab -
-}
diff --git a/steps/crontab/add b/steps/crontab/add
new file mode 100644
index 0000000..83d1a97
--- /dev/null
+++ b/steps/crontab/add
@@ -0,0 +1,12 @@
+step_taken() {
+	crontab -l | grep -Fxq "$(format_crontab_ln "$@")"
+}
+
+take_step() {
+	# 'crontab -' is not in POSIX
+	format_crontab_rec "$@" | crontab -
+}
+
+format_crontab_rec() {
+	printf '%s\t%s\t%s\t%s\t%s\t%s' "$@"
+}