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.
Asked
Active
Viewed 8,366 times
5
-
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 Answers
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
-
-
Thanks @Kerberos. I tried this 0 14 30 * * sh /Library/Agents/_wrk/OldFilesDelete.sh But nothing happened – A M N Kumari Aug 07 '18 at 08:56
-
-
@AMNKumari, your cron is triggered only montly, for daily you must add an * at the day_of_month camp. – Kerberos Aug 07 '18 at 08:58
-
Use `env EDITOR=nano crontab -e` instead of `crontab -e`, if you prefer vim you can use vim instead of nano in the command – Kerberos Aug 07 '18 at 09:04
-
@AMNKumari, if you want to start daily at 11:03am you can use: `3 11 * * * sh /yourPath/yourScript.sh` – Kerberos Aug 07 '18 at 09:06
-
i had entered it. so after that how i know its working or not. its not showing any message. – A M N Kumari Aug 07 '18 at 09:09
-
You can use a test script with `touch asd` that creates a new file. It is normal that it not show nothing after save the crontab. – Kerberos Aug 07 '18 at 09:12
-
@AMNKumari see the edit to show the crontab list and if you want remove it – Kerberos Aug 07 '18 at 09:15
-
After adding the command if you use nano you can use cmd+x and then Y to save, if you use vim you can use `:wq` to save and quit. – Kerberos Aug 07 '18 at 10:11
-
1
-
i entered like this but its not run correct time 48 7 * * * sh /Library/Agents/_wrk/OldFilesDelete.sh – A M N Kumari Aug 08 '18 at 02:36
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
-
Have you typed your script location on 9th line. `
/User/Desktop/test.sh ` – Skull Aug 10 '18 at 14:51