X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=loadcron;fp=loadcron;h=5700cc1ac2f7798aa4130fee2fd4f2a79285e8dd;hb=25d10962e91d178893d773ec2c7e6aaf5415227f;hp=0000000000000000000000000000000000000000;hpb=7b26c9447e6e6b7ef084d85e53bbfbd5bca141f9;p=bin.git diff --git a/loadcron b/loadcron new file mode 100755 index 0000000..5700cc1 --- /dev/null +++ b/loadcron @@ -0,0 +1,46 @@ +#!/bin/sh +# Construct a crontab based on files in ~/.cron and load it into cron. +# The file ~/.cron/username/fqdn is appended to the common file in the same +# directory. Note that the common file may have "$HOME" in it, as in +# "PATH=$HOME/bin". cron is too dumb to deal with that, so the expansion is +# handled by this script. +set -e + +WARNING="# Automatically generated by loadcron; edit ~/.cron/ files instead." + +if [ ! -z "`crontab -l`" ] && ! crontab -l | grep -q "$WARNING"; then + if [ "$1" != "-f" ]; then + echo "loadcron: Current crontab was not generated by loadcron; not changing." >&2 + echo "loadcron: Use loadcron -f to override" + exit + else + crontab -l > $HOME/tmp/oldcrontab + echo "loadcron: Old crontab is backed up to $HOME/tmp/oldcrontab" + fi +fi + +dir=$HOME/.cron/`whoami` +if [ -d "$dir" ]; then + ( + echo "$WARNING" + echo + if [ -e "$dir/common" ]; then + echo "# From $dir/common:" + sed "s!\$HOME!$HOME!" < "$dir/common" + echo + fi + hostfile="$dir/`hostname -f`" + if [ -e "$hostfile" ]; then + echo "# From $hostfile:" + cat "$hostfile" + echo + fi + # debian-edu crontab + debianedufile=/org/alioth.debian.org/chroot/home/groups/debian-edu/cronjobs/crontab.alioth + if [ "$(hostname)" = "haydn" ] && [ -e "$debianedufile" ]; then + echo "# From $debianedufile:" + cat "$debianedufile" + echo + fi + ) | crontab - +fi