]> git.donarmstrong.com Git - bin.git/commitdiff
add joeyh's loadcron
authorDon Armstrong <don@donarmstrong.com>
Wed, 5 Apr 2006 00:52:49 +0000 (00:52 +0000)
committerDon Armstrong <don@donarmstrong.com>
Wed, 5 Apr 2006 00:52:49 +0000 (00:52 +0000)
loadcron [new file with mode: 0755]

diff --git a/loadcron b/loadcron
new file mode 100755 (executable)
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