]> xenbits.xensource.com Git - osstest.git/commitdiff
crontabs: Provide way to install crontabs, with a safety catch
authorIan Jackson <ian.jackson@eu.citrix.com>
Mon, 28 Sep 2015 10:12:27 +0000 (11:12 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 29 Sep 2015 15:25:28 +0000 (16:25 +0100)
With this setup you can say
  ./mg-crontab-install CRONTAB
or even
  ./crontab
  ./crontab-cambridge

And you can't accidentally install the intended crontab on the wrong
host, etc.  (As I did recently!)

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
crontab [changed mode: 0644->0755]
crontab-cambridge [changed mode: 0644->0755]
mg-crontab-install [new file with mode: 0755]

diff --git a/crontab b/crontab
old mode 100644 (file)
new mode 100755 (executable)
index b9d4ad1..6fd5704
--- a/crontab
+++ b/crontab
@@ -1,3 +1,6 @@
+#!/bin/bash ./mg-crontab-install
+#@@ osstest@osstest.test-lab.xenproject.org
+
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 MAILTO=ian.jackson@citrix.com,ian.campbell@eu.citrix.com
 # m            h       dom mon dow     command
old mode 100644 (file)
new mode 100755 (executable)
index b45c0dd..2ababb0
@@ -1,3 +1,6 @@
+#!/bin/bash ./mg-crontab-install
+#@@ osstest@osstest.xs.citrite.net
+
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 MAILTO=ian.jackson@citrix.com,ian.campbell@eu.citrix.com
 # m            h       dom mon dow     command
diff --git a/mg-crontab-install b/mg-crontab-install
new file mode 100755 (executable)
index 0000000..5a59d45
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+# usage: ./mg-crontab-install CRONTAB
+#
+# where CRONTAB is a file containing a line
+#  #@@ USER@HOSTFQDN
+
+set -e -o posix
+
+case "$#.$1" in
+1.[^-]*) crontab="$1"; shift ;;
+*) echo >&2 "bad usage"; exit 1 ;;
+esac
+
+expect="#@@ "
+expect+="`whoami`"
+expect+="@"
+expect+="`hostname -f`"
+
+if ! grep -xF "$expect" "$crontab" >/dev/null; then
+       exec >&2
+       echo "running as: $expect"
+       printf "file is for: "
+       grep '^#@@' "$crontab" || echo "no #@@ line?"
+       exit 2
+fi
+
+crontab "$crontab"
+echo "crontab installed ($expect)"