Skip to content

Instantly share code, notes, and snippets.

@zafergurel
Created July 11, 2019 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zafergurel/12a09caa51c80cd8c86f745c5fa4dfc9 to your computer and use it in GitHub Desktop.
Save zafergurel/12a09caa51c80cd8c86f745c5fa4dfc9 to your computer and use it in GitHub Desktop.
A bash script to programmatically add a cron job to crontab
#!/usr/bin/env bash
cron_line="<cron line to search for>"
cronjob=`crontab -l | grep "$cron_line"`
if [[ -z $cronjob ]]
then
crontab -l > /tmp/mycron
echo -e "\n$cron_line" >> /tmp/mycron
crontab /tmp/mycron
rm /tmp/mycron
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment