#!/bin/sh
# docron - Excute les jobs cron systme quotidiens, hebdomadaires, et
#   mensuels sur un systme susceptible d'tre teint au moment habituel
#   d'excution des jobs cron.

rootcron="/etc/crontab"

if [ $# -ne 1 ] ; then 
  echo "Syntaxe: $0 [daily|weekly|monthly]" >&2 
  exit 1
fi

if [ "$(id -u)" -ne 0 ] ; then    # on peut aussi crire $(whoami) != "root" ici
  echo "$0: il faut excuter cette commande en tant que root" >&2 
  exit 1
fi

job="$(awk "NR > 6 && /$1/ { for (i=7;i<=NF;i++) print \$i }" $rootcron)"

if [ -z $job ] ; then 
  echo "$0: Erreur: aucun job de type $1 trouv dans $rootcron" >&2 
  exit 1
fi

SHELL=/bin/sh         # par cohrence avec la valeur par dfaut de cron

eval $job
