How to add a crontab job to crontab using a bash script

4

I suggest you read Cron and Crontab usage and examples .

And you can run this:

➜ ( printf -- '0 4 8-14 * *  test $(date +%u) -eq 7 && echo "2nd Sunday"' ) | crontab
➜  crontab -l
0 4 8-14 * *  test $(date +) -eq 7 && echo "2nd Sunday"            

Or

#!/bin/bash
cronjob="* * * * * /path/to/command"
(crontab -u userhere -l; echo "$cronjob" ) | crontab -u userhere -

Hope this helps.

Source https://stackoverflow.com/questions/42198960/how-to-add-a-crontab-job-to-crontab-using-a-bash-script
Comments