<< Hide Menu

When setting up multiple automated jobs via CRON on a machine I use a central call-script to make logging and calling easier.

For a simple case, here is my call script for two jobs:

#!/usr/bin/bash

export DATE=`date '+%m%d.%H%M%S'`
export DATE_SHORT=`date '+%m%d'`
export LOGDIR="/var/log/caller"

case "$1" in

#######################################################################
# Auto-Update of Let's Encrypt Certificates
#######################################################################
certbot_renew)
  certbot renew --no-self-upgrade  1>>  ${LOGDIR}/certbot_${DATE}.log 2>&1

;;

#######################################################################
# Backup of Web Configuration
#######################################################################
backup_web)
    echo "Backup Web"
    tar -cvzf /data/backup/backup_${DATE}.tar.gz /etc /home /var/www /usr/local/bin 1>>  ${LOGDIR}/backup_${DATE} 2>&1
    scp /data/backup/backup_${DATE}.tar.gz some-backup-server:/backup/webserver/    1>>  ${LOGDIR}/backup_${DATE} 2>&1
;;


#######################################################################
# Otherwise list configured jobs
#######################################################################
*)
    echo
    echo "Cron Call Interface"
    echo "Usage : call.sh <JOB>"
    echo 
    echo "Job '$1' ist undefined"
    echo 
    echo "Configured Jobs :"
    echo ----------------------
    cat $0 |grep "^.*)$"| grep -v "^ "|sed "s/[)]//g;s/^ */  - /"|grep -v "*"
    echo 
;;   

esac

And then in the crontab there are just calls to that script:

# Automated Certificate Renewal
29  * * * * /usr/local/bin/call.sh certbot_renew 1>/dev/null 2>&1

# Backup Web Server Configuration
10 03 * * * /usr/local/bin/call.sh backup_web    1>/dev/null 2>&1