To add a new cron job, follow these steps:
-
Open the Crontab for Editing:
Use the following command to open the crontab file in the default text editor:crontab -e -
Add a New Cron Job:
In the editor, add a new line for your cron job in the following format:* * * * * /path/to/your/commandThe five asterisks represent:
- Minute (0-59)
- Hour (0-23)
- Day of Month (1-31)
- Month (1-12)
- Day of Week (0-7) (Sunday is both 0 and 7)
For example, to run a script located at
/home/user/script.shevery day at 5 PM, you would add:0 17 * * * /home/user/script.sh -
Save and Exit:
After adding your cron job, save the file and exit the editor. The method to save and exit depends on the text editor you are using (e.g.,:wqforvi,CTRL + Xfollowed byYfornano). -
Verify the New Cron Job:
You can verify that your new cron job has been added by listing the current cron jobs:crontab -l
That's it! Your new cron job is now scheduled to run at the specified times.
