How to schedule job on Ubuntu?

Thu, Aug 20, 2020 2-minute read

For scheduling job you should use Cron. It is a time-based job scheduler.

Crontab is a file where jobs are descirbed. You can edit this by calling command:

crontab -e

During first call you can be asked about default text editor. I chose VIM. Each line contains cron expression - the expression which describe frequency of command calling.

# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │                                   7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * <command to execute>

You can turn off temporarly some job by commenting it in crontab file or you can turn off cron service for turning off all jobs:

sudo service cron stop

If you want to call some shell script by cron, you have to add execute privilege to this script

chmod +x /path/to/script

Useful resources:

Newsletter

Thank you for visiting my website. I hope you enjoyed content which I prepared and learned something valuable from it. If you want to be informed about my next entries or occasionally get a message with a collection of some interesting links, please subscribe to my newsletter. I will be extremely pleased if you do this and join my community!

  • By clicking button below you agree to send you news from my blog, about my products and services. Above data are stored in Mailchimp and I do not share them to anyone. More info you can find in privacy policy.