How to add a new cron job?

To add a new cron job, follow these steps:

  1. Open the Crontab for Editing:
    Use the following command to open the crontab file in the default text editor:

    crontab -e
  2. Add a New Cron Job:
    In the editor, add a new line for your cron job in the following format:

    * * * * * /path/to/your/command

    The 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.sh every day at 5 PM, you would add:

    0 17 * * * /home/user/script.sh
  3. 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., :wq for vi, CTRL + X followed by Y for nano).

  4. 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.

0 Comments

no data
Be the first to share your comment!