5

I am using Mac Os x. I have an shell script and i want to run this automatically daily for given time. Is there anyway to do this without using third party tool.

A M N Kumari
  • 79
  • 2
  • 7
  • Dupes a question on superuser - https://superuser.com/questions/126907/how-can-i-get-a-script-to-run-every-day-on-mac-os-x – Warren Burton Aug 07 '18 at 08:40
  • Duplicate of https://stackoverflow.com/questions/36854193/scheduling-a-terminal-command-or-script-file-to-run-daily-at-a-specific-time-mac – Jim DeLaHunt Dec 15 '21 at 07:56

2 Answers2

11

Yes of course, you can use crontab!

Firstly open the terminal, then launch crontab with:

crontab -e

In some cases you need to specify the editor (es.nano) like this:

env EDITOR=nano crontab -e

Now you can add your daily script at 3am like this:

0  3  *  *  *  sh /path/to/your/file

The format is:

min  hour  day_of_month  month  day_of_week  your_command

After save the cron, you can check the crontab list whit:

crontab -l

And if you want remove it with:

crontab -r
Kerberos
  • 4,036
  • 3
  • 36
  • 55
1

You can do this via LaunchDaemons

Just create a file with below syntax and put on /Library/LaunchDaemons/ and save it in .plist

now script will run every 13:30 Hours - you can change time what ever you want

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>COM.COMPANY.LOGGER</string>
    <key>ProgramArguments</key>
    <array>
        <string>YOUR-SCRIPT-LOCATION</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
          <key>Hour</key>
          <integer>13</integer>
          <key>Minute</key>
          <integer>15</integer>
    </dict>
</dict>
</plist>
Skull
  • 157
  • 16