+91-98987 22266 | Blog

Mac OS X - Schedule cron jobs with crontab from Terminal

Running scripts on my Macbook Air was a challenge for me . I did some research and found that if you are on a Mac (or Linux), you can use crontab , which is a scheduling tool that will run jobs (scripts) at regular intervals.

crontab

Cronjob to crontab can be edited by editing the job list.We can specify the cronjob in the following format (first line): crontab

We can understand by using a simple example job. Lets create a simple cronjob to copy a particular file say "mysecretfile.txt" to a particular folder say "secretfolder" , and set this up to run once a day.
We'll set it to run as a cronjob by editing the job list (with the nano editor)

env EDITOR=nano crontab -e

Now enter the following and press CTRL + O and CTRL + X to save and exit.

0 12 * * * cp ~/mysource-folder/mysecretfile.txt ~/secretfolder/

This will execute the command every day at 12:00, which changes to the folder of the file and copies it.

Notice that if your computer is shut down or sleeping at the time, the script will not run until the next day at the specified time.

To see a list of your active crontab jobs, use the following command:

crontab -l

Disable email alerts

So after everything is set up, you might notice that the Terminal suddenly have started sending you e-mails.

You can disable this behaviour by inserting this line at the very top of your crontab file:

MAILTO=""

About TechnoIntellects

We are reputed Website Design, Development and Marketing agency with more than 16 years of experience. Read more

Keep in Touch

 

  contact (@) technointellects.com
  +91-9898 722266
  Ahmedabad,Gujarat, India

 

Get Map

TechnoIntellects WebSite Consultancy

Our Latest Blog

Feed not found.