如何查看 Linux Cron Jobs ?
Cron 这个名字来源于希腊单词 Chronos,用来表示时间。它是 Linux 系统的一个守护进程,用于按指定的时间间隔自动执行命令或脚本。本文将介绍如何查看 Linux 中运行的 Cron Jobs,希望对你有用。
List Current User Cron Jobs
列出当前用户的所有 Cron Jobs,使用如下命令:
crontab –l
用户的 cron jobs 通常位于 /var/spool/cron/crontabs 目录下,存储在以用户名命名的单独文件下。
List Other User Cron Jobs
root 或 sudo 用户也可以查看其他用户的 Cron Jobs,使用如下命令:
sudo crontab –u username –l
List System Cron Jobs
以 root 或 sudo 帐户可以查看系统的 Cron Jobs,使用如下命令:
less /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
# 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
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 )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
List Hourly Cron Jobs
ls -la /etc/cron.hourly
输出如下:
total 20
drwxr-xr-x 2 root root 4096 Apr 23 2020 .
drwxr-xr-x 142 root root 12288 Jan 19 15:21 ..
-rw-r--r-- 1 root root 102 Feb 14 2020 .placeholder
List Daily Cron Jobs
ls -la /etc/cron.daily
输出如下:
total 72
drwxr-xr-x 2 root root 4096 Dec 28 15:28 .
drwxr-xr-x 142 root root 12288 Jan 19 15:21 ..
-rwxr-xr-x 1 root root 311 Jul 16 2019 0anacron
-rwxr-xr-x 1 root root 539 Apr 13 2020 apache2
-rwxr-xr-x 1 root root 376 Dec 5 2019 apport
-rwxr-xr-x 1 root root 1478 Apr 9 2020 apt-compat
-rwxr-xr-x 1 root root 355 Dec 29 2017 bsdmainutils
-rwxr-xr-x 1 root root 384 Nov 19 2019 cracklib-runtime
-rwxr-xr-x 1 root root 1187 Sep 6 2019 dpkg
-rwxr-xr-x 1 root root 377 Jan 21 2019 logrotate
-rwxr-xr-x 1 root root 1123 Feb 25 2020 man-db
-rw-r--r-- 1 root root 102 Feb 14 2020 .placeholder
-rwxr-xr-x 1 root root 4574 Jul 18 2019 popularity-contest
-rwxr-xr-x 1 root root 383 Jan 6 2020 samba
-rwxr-xr-x 1 root root 214 Apr 2 2020 update-notifier-common
List Weekly Cron Jobs
ls -la /etc/cron.weekly
输出如下:
total 32
drwxr-xr-x 2 root root 4096 Apr 23 2020 .
drwxr-xr-x 142 root root 12288 Jan 19 15:21 ..
-rwxr-xr-x 1 root root 312 Jul 16 2019 0anacron
-rwxr-xr-x 1 root root 813 Feb 25 2020 man-db
-rw-r--r-- 1 root root 102 Feb 14 2020 .placeholder
-rwxr-xr-x 1 root root 211 Apr 2 2020 update-notifier-common
List Montly Cron Jobs
ls -la /etc/cron.monthly
输出如下:
total 24
drwxr-xr-x 2 root root 4096 Apr 23 2020 .
drwxr-xr-x 142 root root 12288 Jan 19 15:21 ..
-rwxr-xr-x 1 root root 313 Jul 16 2019 0anacron
-rw-r--r-- 1 root root 102 Feb 14 2020 .placeholder
我的开源项目
评论已关闭