Last active
April 20, 2019 19:54
-
-
Save PieterScheffers/0fc44696fcc45761a2b3f9c111bd33b0 to your computer and use it in GitHub Desktop.
Add entry to crontab with script
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 sh | |
# http://stackoverflow.com/questions/878600/how-to-create-cronjob-using-bash | |
# http://stackoverflow.com/questions/4880290/how-do-i-create-a-crontab-through-a-script | |
# http://stackoverflow.com/questions/14450866/search-for-a-cronjob-with-crontab-l/14451184#14451184 | |
JOB='*/5 * * * * /path/to/job -with args' | |
FINDJOB=$(crontab -l | grep -F "$JOB") | |
echo " " | |
if [ -z "$FINDJOB" ] | |
then | |
echo "Cron job doesn't exist yet, adding it to crontab" | |
(crontab -l 2>/dev/null; echo "$JOB") | crontab - | |
else | |
echo "Cron job already added!" | |
fi | |
echo " " | |
echo "Contents of crontab: (crontab -l)" | |
crontab -l | |
echo " " | |
echo "To edit cron manually, execute: 'crontab -e'" | |
echo " " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment