Created
August 17, 2022 12:33
-
-
Save PSJoshi/d0d289294bc45cf5cabacd55818044f7 to your computer and use it in GitHub Desktop.
Cron job using bash 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
### Cron job using bash script | |
``` | |
#!/bin/sh | |
crontab -l > cron_backup | |
echo "0 10 * * * sudo /home/<user>/job.sh >/dev/null 2>&1" >> cron_backup | |
crontab cron_backup | |
rm cron_backup | |
``` | |
Another version | |
``` | |
#!/bin/bash | |
(crontab -l; echo "0 10 * * * /home/<user>/job.sh") | sort -u | crontab - | |
``` | |
Ref - https://www.baeldung.com/linux/create-crontab-script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment