adding mail
[james-home.git] / bin / loadcron
blob40bcb214c0dddc95dfeb4a49387caa8d5a679425
1 #!/bin/sh
2 # Construct a crontab based on files in ~/.cron and load it into cron.
3 # The file ~/.cron/username/fqdn is appended to the common file in the same
4 # directory. Note that the common file may have "$HOME" in it, as in
5 # "PATH=$HOME/bin". cron is too dumb to deal with that, so the expansion is
6 # handled by this script.
7 set -e
9 WARNING="# Automatically generated by loadcron; edit ~/.cron/ files instead."
11 if [ ! -z "`crontab -l`" ] && ! crontab -l | grep -q "$WARNING"; then
12 if [ "$1" != "-f" ]; then
13 echo "loadcron: Current crontab was not generated by loadcron; not changing." >&2
14 echo "loadcron: Use loadcron -f to override"
15 exit 1
16 else
17 crontab -l > $HOME/tmp/oldcrontab
18 echo "loadcron: Old crontab is backed up to $HOME/tmp/oldcrontab"
22 dir=$HOME/.cron/`whoami`
23 if [ -d "$dir" ]; then
24 hostfile="$dir/`hostname -f`"
25 # if [ ! -e "$hostfile" ]; then
26 # echo "loadcron: $hostfile does not exist, not loading" >&2
27 # fi
30 echo "$WARNING"
31 echo
32 if [ -e "$dir/common" ]; then
33 echo "# From $dir/common:"
34 sed "s!\$HOME!$HOME!" < "$dir/common"
35 echo
37 hostfile="$dir/`hostname -f`"
38 if [ -e "$hostfile" ]; then
39 echo "# From $hostfile:"
40 cat "$hostfile"
41 echo
43 # debian-edu crontab
44 debianedufile=/org/alioth.debian.org/chroot/home/groups/debian-edu/cronjobs/crontab.alioth
45 if [ "$(hostname)" = "haydn" ] && [ -e "$debianedufile" ]; then
46 echo "# From $debianedufile:"
47 cat "$debianedufile"
48 echo
50 ) | crontab -