Skip to content

Instantly share code, notes, and snippets.

@vdudouyt
Last active December 31, 2015 11:49
Show Gist options
  • Save vdudouyt/7982559 to your computer and use it in GitHub Desktop.
Save vdudouyt/7982559 to your computer and use it in GitHub Desktop.
Programmatically add cronjob with Shell
add_cronjob() {
if [[ `crontab -l|grep "$2"` ]]; then
echo "Cronjob already exists, do not adding"
return
fi
(crontab -l; echo "$1" "$2")|crontab -
}
# add_cronjob '*/1 * * * *' 'cd /var/www/cgi-bin/ && ./run.sh 2>&1 >/dev/null'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment