本文共 1460 字,大约阅读时间需要 4 分钟。
Linux 系统中的计划任务安排其实是由 crond
这个守护进程负责的。安装完操作系统后,这个服务会自动启用,并且每分钟会循环检查是否有任务需要执行。如果有,就自动运行相应的指令。对于那些习惯了 Windows 的计划任务安排的人来说,crontab
命令可能会显得有点陌生,但它是 Linux系统下的核心工具之一。
在 Linux 中,crontab
命令允许用户定义计划任务,使用的语法规则包含以下几个关键要素:
crontab
命令中的时间单位包括:
* * * * * your_command
3,15 * * * * your_command
3,15 8-11 * * * your_command
3,15 8-11 */2 * * * your_command
0 11 * * 1 your_command
30 21 * * * /etc/init.d/smb restart
45 4 1,10,22 * * your_command
10 1 * * 6,0 your_command
0,30 18-23 * * * your_command
0 23 * * 6 your_command
*oresolving cron job execution each hour.*/1 * * * * /etc/init.d/smb restart
23-7/1 * * * your_command
0 11 4 * mon-wed your_command
0 4 1 jan your_command
01 * * * * root run-parts /etc/cron.hourly
了解了 crontab
的基本语法以后,可以根据自己的需求灵活调整时间参数。例如,为特定服务器重启服务、定期备份文件、执行系统检查等都能通过 crontab
实现。crontab
的高灵活性使其成为 Linux系统管理员和开发者的必备工具。
转载地址:http://qnngz.baihongyu.com/