Created
December 15, 2021 10:53
-
-
Save fjahn/85d80126e10f6847d59bd51e18d8abee to your computer and use it in GitHub Desktop.
Add Cronjob via bash
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
#!/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