How to schedule cron Jobs in Linux for Task Scheduling

How to schedule cron Jobs in Linux for Task Scheduling

Cron is a built-in scheduling utility in Linux that allows you to schedule tasks to run periodically at fixed times, dates, or intervals.

To create a cron job, open a terminal window on your ubuntu system.

1. Edit the cron table for the current user by running:

This will open the default text editor (usually nano or vi) with the user’s cron jobs.

2. The syntax for a cron job entry consists of five fields followed by the command to be executed:

* * * * * command_to_execute

The five fields represent minute, hour, day of the month, month, and day of the week, respectively.

You can use asterisks (*) to specify “any” value or specify individual values or ranges. For example:

· ‘*’ in the minute field means “every minute”.

· ‘0’ in the hour field means “at the start of every hour”.

· ‘*’ in the day of the month field means “every day”.

· ‘*’ in the month field means “every month”.

· ‘1-5’ in the day of the week field means “Monday to Friday”.

3. Add your desired cron job entry to the file. For example, to run a script database backup.sh located in your /home/msa/ directory every day at 9:30 PM, you would add:

4. After adding your cron job in nano editor to save and close a file in the nano text editor, you can follow these steps:

Press Ctrl + O (the letter “O”, not zero) to write the current contents to a file.

Press Enter to confirm the filename (or modify it if you wish).

Press Ctrl + X to exit nano.

After completing these steps, you’ll have successfully saved and closed the file in the nano editor.

The cron daemon will automatically reload the cron table, and your cron job will be scheduled to run according to the specified schedule.

5. You can view your current cron jobs by running:


This will list all cron jobs for the current user.

That’s it! You have now set up a cron job to automate a repetitive task on your Ubuntu system. Make sure to test your cron job to ensure it runs as expected at the specified schedule.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *