Skip to content

crontab MacOS command

The crontab command on MacOS allows users to schedule tasks at regular intervals, automating processes efficiently. By using a simple syntax, users can set up specific commands to run at designated times without manual intervention. Understanding how to navigate and manipulate the crontab file empowers users to streamline their workflows and optimize productivity. With the flexibility and power of the crontab command, MacOS users can automate routine tasks and ensure timely execution of critical operations. Utilizing this feature effectively can enhance efficiency and organization within a user’s computing environment.

crontab Syntax:

Terminal window
crontab [options] [parameters]

Options:

OptionDescription
-lDisplay the current user’s crontab entries.
-eEdit the current user’s crontab entries.
-rRemove the current user’s crontab entries.

Parameters:

ParameterDescription
filenameSpecifies the file to use for crontab.

crontab bash Examples:

Schedule a script to run every hour

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

This example schedules the script “script.sh” to run every hour.

Schedule a backup to run every day at midnight

Terminal window
0 0 * * * /path/to/backup.sh

This example schedules the backup script “backup.sh” to run every day at midnight.

Send a notification every weekday at 9:00 AM

Terminal window
0 9 * * 1-5 /path/to/notify.sh

This example schedules the notification script “notify.sh” to run every weekday at 9:00 AM.

Run a command every 30 minutes during office hours

Terminal window
*/30 9-17 * * * /path/to/command.sh

This example runs the command script “command.sh” every 30 minutes between 9:00 AM and 5:00 PM.

Schedule a monthly report to run on the 1st of every month

Terminal window
0 0 1 * * /path/to/report.sh

This example schedules the monthly report script “report.sh” to run on the 1st of every month.

Reboot the system every Sunday at 3:00 AM

Terminal window
0 3 * * 0 /sbin/shutdown -r now

This example schedules the system to reboot every Sunday at 3:00 AM.

How do I use crontab in MacOS?

To use the crontab command in MacOS, execute the following command:

Terminal window
crontab --e

How do I list the current cron jobs in MacOS?

To list the current cron jobs in MacOS, run the following command:

Terminal window
crontab -l

How do I remove all cron jobs in MacOS?

To remove all cron jobs in MacOS, you can run the following command:

Terminal window
crontab -r

How do I edit a cron job for a specific user in MacOS?

To edit a cron job for a specific user in MacOS, use the following command:

Terminal window
crontab -u <username> -e

How do I run a cron job every hour in MacOS?

To run a cron job every hour in MacOS, you can set up the cron job using the following syntax:

Terminal window
0 * * * * /path/to/command

How do I run a cron job every day at a specific time in MacOS?

To run a cron job every day at a specific time in MacOS, set up the cron job like this:

Terminal window
0 12 * * * /path/to/command

How do I run a cron job every week on a specific day in MacOS?

To run a cron job every week on a specific day in MacOS, set up the cron job using the following format:

Terminal window
0 0 * * 1 /path/to/command

How do I run a cron job every month on a specific day and time in MacOS?

To run a cron job every month on a specific day and time in MacOS, set up the cron job like this:

Terminal window
0 12 1 * * /path/to/command

Applications of the crontab command

  • Scheduling repetitive tasks
  • Running maintenance scripts
  • Automating backups
  • Updating system and software
  • Monitoring system performance
  • Sending automated emails
  • Controlling system processes