Skip to content

Instantly share code, notes, and snippets.

@c80609a
Forked from marcostolosa/addCron.md
Created April 18, 2019 13:24
Show Gist options
  • Save c80609a/2cec990b4371704211f9659d8ca61b81 to your computer and use it in GitHub Desktop.
Save c80609a/2cec990b4371704211f9659d8ca61b81 to your computer and use it in GitHub Desktop.
Create a Cron Job Using Bash (Shell Script) Automatically Without Interactive Editor

Adding a Cron Job via Shell Script

#write out current crontab
crontab -l > mycron

#echo new cron into cron file
echo "00 09 * * 1-5 echo hello" >> mycron

#install new cron file
crontab mycron
rm mycron

Another usages

$(crontab -l && echo "0 0 0 0 0 some entry") | crontab -


Cron line Explanation

* * * * * "command to be executed"
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment