Skip to content

Instantly share code, notes, and snippets.

@fjahn
Created December 15, 2021 10:53
Show Gist options
  • Save fjahn/85d80126e10f6847d59bd51e18d8abee to your computer and use it in GitHub Desktop.
Save fjahn/85d80126e10f6847d59bd51e18d8abee to your computer and use it in GitHub Desktop.
Add Cronjob via bash
#!/bin/bash
# Idea stolen from https://stackoverflow.com/questions/610839/how-can-i-programmatically-create-a-new-cron-job#13355743
addCronjob() {
user=$(whoami)
(crontab -u "$user" -l 2>/dev/null || echo '' ; echo "$1") \
| sort - \
| uniq - \
| crontab -u "$user" -
}
# Usage
addCronjob "* * * * * echo 'boop'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment