crontabs: Provide way to install crontabs, with a safety catch
PATCH 1/1 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 <[email protected]>
--- 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
crontab +3 -0
@@ -1,3 +1,6 @@ +#!/bin/bash ./mg-crontab-install +#@@ [email protected] + PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin [email protected],[email protected] # m h dom mon dow command
crontab-cambridge +3 -0
@@ -1,3 +1,6 @@ +#!/bin/bash ./mg-crontab-install +#@@ [email protected] + PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin [email protected],[email protected] # m h dom mon dow command
mg-crontab-install new file +28 -0
@@ -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)"
Signature · 1 line
1.7.10.4
Quoted 10 lines · Ian Jackson
With this setup you can say
./mg-crontab-install CRONTAB
or even
./crontab
./crontab-cambridgeAnd you can't accidentally install the intended crontab on the wrong host, etc. (As I did recently!)
Signed-off-by Ian Jackson <[email protected]>
Acked-by Ian Campbell <[email protected]>