作为一个php码农,linux接触总是很少,但又是必须会的一项技能,今天学到的linux命令是crontab命令。
注:以下总结基于Ubuntu 12.04
先去Ubuntu的/etc目录下看看,我们都知道/etc目录主要用来存放系统中的配置文件,基本上所有的配置文件都可以在这里找到。运行以下命令看看:
ls /etc/cron*这个命令会列出/etc目录下所有以cron开头的文件和文件夹。可以看到主要有以下文件夹:
/etc/cron.hourly 这里存放了每小时需要运行的脚本 /etc/cron.daily 这里存放了每天需要运行的脚本 /etc/cron.weekly 这里存放了每个星期需要运行的脚本 /etc/cron.monthly 这里存放了每月需要运行的脚本 /etc/cron.d 如果既不是按小时,也不按天,周和月来运行,就放在这个文件夹原来,我们可以把我们需要定时运行的脚本放到对应的文件夹中,系统就会定时运行对应的脚本了。那么系统是怎么做到的呢?
在/etc目录下,还有一个crontab文件,该文件内容如下:
# /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )转载于:https://www.cnblogs.com/gyfluck/p/5801807.html
