Created
July 11, 2019 12:45
-
-
Save zafergurel/12a09caa51c80cd8c86f745c5fa4dfc9 to your computer and use it in GitHub Desktop.
A bash script to programmatically add a cron job to crontab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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