如何在 Cron / Crontab 中显示(列出)所有作业

服务器可以自动执行您必须自己执行的任务,例如运行脚本。 在 Linux 云专用服务器或 VPS 服务器上, cron 实用程序是自动化脚本运行的首选方式。 在本文中,我们将介绍如何查看 crontab 列表中安排的作业。 有关 Cron 的介绍,请查看我们的知识库如何:使用 Cron 自动化服务器脚本。 知道如何设置 crontab 是一项重要技能,但即使您不编辑这些内容,知道如何查看它们也很重要。

如何在 Crontab 中查看作业

查看 root 的 cron 作业。

crontab -l

查看用户的 cron 作业。

crontab -u username -l

用户 testuser 的示例。

crontab -u testuser -l

查看每日 Cron 作业

查看所有每日 cron 作业。

ls -la /etc/cron.daily/

查看特定的每日 cron 作业。

less /etc/cron.daily/filename

文件名为 logrotate 的示例。

less /etc/cron.daily/logrotate

查看每小时 Cron 工作

首先查看所有每小时的 cron 作业。

ls -la /etc/cron.hourly/

然后查看特定的每小时 cron 作业。

less /etc/cron.hourly/filename

文件名为 0anacron 的示例。

less /etc/cron.hourly/0anacron

查看每周 Cron 作业

首先查看所有每周的 cron 作业。

ls -la /etc/cron.weekly/

然后查看特定的每周 cron 作业。

less /etc/cron.weekly/filename

文件名为weeklyexample 的示例。

less /etc/cron.weekly/weeklyexample

查看每月 Cron 作业

首先查看所有每月的 cron 作业。

ls -la /etc/cron.monthly/

然后查看特定的每月 cron 作业。

less /etc/cron.monthly/filename

文件名为 readahead-monthly.cron 的示例。

less /etc/cron.monthly/readahead-monthly.cron

查看 /etc/crontab

less /etc/crontab

示例结果。

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- 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
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

当一个标准 Cloud VPS 是不够的,Liquid Web 的 HIPAA 兼容网络托管使用我们的专用服务器是梦想成真。 Liquid Web 的服务器在性能和支持方面胜过竞争对手。 看看我们的专用服务器如何让您的网站性能飙升。

贾斯汀帕尔默的视频更新