Adding to Crontab in Bash

Here’s a neat command to append a job to a crontab within a Bash script.

crontab -l | { cat; echo "0 1 * * * /dir/script.sh > /logs/script.cronlog 2>&1"; } | crontab -

To validate, perform crontab -l to see if your changes are there.

crontab -l