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>
+#!/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
+#!/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
--- /dev/null
+#!/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)"