[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [OSSTEST PATCH] crontabs: Provide way to install crontabs, with a safety catch



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@xxxxxxxxxxxxx>
---
 crontab            |    3 +++
 crontab-cambridge  |    3 +++
 mg-crontab-install |   28 ++++++++++++++++++++++++++++
 3 files changed, 34 insertions(+)
 mode change 100644 => 100755 crontab
 mode change 100644 => 100755 crontab-cambridge
 create mode 100755 mg-crontab-install

diff --git a/crontab b/crontab
old mode 100644
new mode 100755
index b9d4ad1..6fd5704
--- a/crontab
+++ b/crontab
@@ -1,3 +1,6 @@
+#!/bin/bash ./mg-crontab-install
+#@@ osstest@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 MAILTO=ian.jackson@xxxxxxxxxx,ian.campbell@xxxxxxxxxxxxx
 # m            h       dom mon dow     command
diff --git a/crontab-cambridge b/crontab-cambridge
old mode 100644
new mode 100755
index b45c0dd..2ababb0
--- a/crontab-cambridge
+++ b/crontab-cambridge
@@ -1,3 +1,6 @@
+#!/bin/bash ./mg-crontab-install
+#@@ osstest@xxxxxxxxxxxxxxxxxxxxxx
+
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 MAILTO=ian.jackson@xxxxxxxxxx,ian.campbell@xxxxxxxxxxxxx
 # m            h       dom mon dow     command
diff --git a/mg-crontab-install b/mg-crontab-install
new file mode 100755
index 0000000..5a59d45
--- /dev/null
+++ b/mg-crontab-install
@@ -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)"
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.