How To Add Jobs To cron Under Linux or UNIX

https://w‮l.ww‬autturi.com
How To Add Jobs To cron Under Linux or UNIX

To add a job to cron under Linux or UNIX, you will need to create a crontab file and specify the schedule and command for the job.

Here are the steps to add a job to cron under Linux or UNIX:

  1. Open a terminal and type the following command to edit the crontab file for the current user:
crontab -e

This will open the crontab file in a text editor. If you don't have a crontab file yet, a new one will be created.

  1. In the crontab file, add a new line with the schedule and command for the job. The schedule is specified using a series of fields that indicate when the job should be run, and the command is the command that should be executed.

Here is an example of a crontab entry that runs a script every day at midnight:

0 0 * * * /path/to/script.sh

The first field ("0") indicates the minute (0-59) at which the job should be run, the second field ("0") indicates the hour (0-23), the third field ("") indicates the day of the month (1-31), the fourth field ("") indicates the month (1-12), and the fifth field ("*") indicates the day of the week (0-6). The command to be executed is specified at the end of the line.

  1. Save the crontab file and exit the text editor.

With these steps, the job should be added to cron and will be executed according to the schedule specified in the crontab file.

Note: You can use the "crontab -l" command to list the jobs in your crontab file, and the "crontab -r" command to remove all the jobs from your crontab file. Consult the cron documentation for more information on the available options and the syntax for specifying the schedule of a cron job.

Created Time:2017-10-28 21:38:49  Author:lautturi