Linux 系統定時任務則是由 cron (crond) 這個系統服務來控制的。用戶可以使用crontab來創建自己的定時任務。
安裝完成操作系統後,默認會安裝此服務工具,並且會自動啓動crond進程,crond進程每分鐘會定期檢查是否有要執行的任務,如果有則自動執行該任務。
使用 crontab 命令,我們可以在固定的間隔時間執行指定的系統指令或 shell 腳本。時間精確到分鐘。一般用作日誌分析和數據的定時備份。
命令參數:
usage: crontab [-u user] file
crontab [-u user] { -e | -l | -r }
-l:列出定時任務
-e:編輯定時任務
-r:刪除定時任務
Mac下可以參考:
The first form of this command is used to install a new crontab from some named file or standard input if the
pseudo-filename `-' is given.
The following options are available:
-u Specify the name of the user whose crontab is to be tweaked. If this option is not given, crontab exam-
ines ``your'' crontab, i.e., the crontab of the person executing the command. Note that su(1) can con-
fuse crontab and that if you are running inside of su(1) you should always use the -u option for
safety's sake.
-l Display the current crontab on standard output.
-r Remove the current crontab.
-e Edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables. The
specified editor must edit the file in place; any editor that unlinks the file and recreates it cannot
be used. After you exit from the editor, the modified crontab will be installed automatically.
FILES
/usr/lib/cron/cron.allow
/usr/lib/cron/cron.deny
DIAGNOSTICS
A fairly informative usage message appears if you run it with a bad command line.
SEE ALSO
crontab(5), compat(5), cron(8), launchctl(1)
STANDARDS
The crontab command conforms to IEEE Std 1003.2 (``POSIX.2''). The new command syntax differs from previous
versions of Vixie Cron, as well as from the classic SVR3 syntax.
AUTHORS
Paul Vixie <[email protected]>
BSD December 29, 1993 BSD