From: Ian Jackson Subject: [OSSTEST PATCH] crontabs: Provide way to install crontabs, with a safety catch Date: Mon, 28 Sep 2015 11:15:31 +0100 Message-ID: <1443435331-22407-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZgVTK-0006uK-Kq for xen-devel@lists.xenproject.org; Mon, 28 Sep 2015 10:15:50 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org 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 --- 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@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 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@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 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