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.
如何在特定时间在Mac Os X中运行shell脚本?我知道它与cron有关,但我无法弄明白。有人可以帮我提供相关代码。
1 个解决方案
#1
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.
crontabs是cron守护进程读取的文件。它们告诉它在不同时间执行操作(例如运行shell脚本)。更多信息在这里。
http://www.macdevcenter.com/pub/a/mac/2001/12/14/terminal_one.html
In a Linux terminal I type:
在Linux终端中我键入:
crontab -e
An example would be
一个例子是
30 4 * * 6 root sh /etc/weekly 2>&1 | tee /var$ …
for a weekly run at 4:30
每周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 ...
所以每天凌晨2点跑foo都会......
0 2 * * * foo
The above tutorial contains OSX instructions for editing your crontab file!
上面的教程包含用于编辑crontab文件的OSX指令!
good luck
See also: http://developer.apple.com/documentation/Darwin/Reference/Manpages/man5/crontab.5.html The OSX crontab man-page
另请参阅:http://developer.apple.com/documentation/Darwin/Reference/Manpages/man5/crontab.5.html OSX crontab手册页
and
#1
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.
crontabs是cron守护进程读取的文件。它们告诉它在不同时间执行操作(例如运行shell脚本)。更多信息在这里。
http://www.macdevcenter.com/pub/a/mac/2001/12/14/terminal_one.html
In a Linux terminal I type:
在Linux终端中我键入:
crontab -e
An example would be
一个例子是
30 4 * * 6 root sh /etc/weekly 2>&1 | tee /var$ …
for a weekly run at 4:30
每周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 ...
所以每天凌晨2点跑foo都会......
0 2 * * * foo
The above tutorial contains OSX instructions for editing your crontab file!
上面的教程包含用于编辑crontab文件的OSX指令!
good luck
See also: http://developer.apple.com/documentation/Darwin/Reference/Manpages/man5/crontab.5.html The OSX crontab man-page
另请参阅:http://developer.apple.com/documentation/Darwin/Reference/Manpages/man5/crontab.5.html OSX crontab手册页
and