简体   繁体   中英

How to run shell script in Mac Os X everyday or set a timing?

How can I run a shell script in Mac Os X at a certain time? I know it is something related to cron but I cannot figure it out. Can someone help me with the relevant code.

crontabs are files read by the cron daemon. They tell it to perform actions (such as running a shell script) at various times. More info here.

http://www.macdevcenter.com/pub/a/mac/2001/12/14/terminal_one.html

In a Linux terminal I type:

crontab -e

An example would be

30  4   *   *   6   root    sh /etc/weekly  2>&1 | tee /var$ …

for a weekly run at 4:30

.---------------- minute (0 - 59) 
|  .------------- hour (0 - 23)
|  |  .---------- day of month (1 - 31)
|  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ... 
|  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat 
|  |  |  |  |
*  *  *  *  *  command to be executed

So every day, running foo at 2:00 would be ...

0  2  *  *  *  foo

The above tutorial contains OSX instructions for editing your crontab file!

good luck

See also: http://developer.apple.com/documentation/Darwin/Reference/Manpages/man5/crontab.5.html The OSX crontab man-page

and

http://en.wikipedia.org/wiki/Cron

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM