One Comment

  1. Fantastic solution, thank you!

    I’ve implemented this into a BASH function:

    “`
    add_cron() {
    # save the entire line in one variable
    line=$*

    # check if line already exists in crontab
    crontab -l | grep “$line” > /dev/null
    status=$?

    if [ $status -ne 0 ]
    then
    echo “adding line …”
    (crontab -l; echo “$line”;) | crontab –
    fi
    }
    “`

    This avoids duplicate adding. You can then add a line like so:
    add_cron “* * * * * /path/to/executable argument_1 argument_2 >/dev/null 2>&1”

    Kind regards,
    Martin.

Leave a Reply

Your email address will not be published. Required fields are marked *