Inspect cron schedules in /etc/cron.*
In addition to the main /etc/crontab
file, many Linux distributions use directories like /etc/cron.d/
, /etc/cron.hourly/
, /etc/cron.daily/
, /etc/cron.weekly/
, and /etc/cron.monthly/
to organize system-wide cron jobs.
These directories provide a more structured way to manage scheduled tasks. Scripts placed in /etc/cron.hourly/
are executed every hour, those in /etc/cron.daily/
are executed every day, and so on. The exact timing is usually controlled by a script in /etc/crontab
that runs these directories periodically.
Let's inspect the contents of these directories to see what system tasks are scheduled.
First, let's list the contents of the /etc/cron.d/
directory. This directory often contains files placed by installed packages that define specific cron jobs.
Type the following command and press Enter:
ls /etc/cron.d/
You might see output similar to this, listing files within the directory:
anacron e2scrub_all phpsessionclean
These files contain cron job definitions, similar in format to /etc/crontab
(including the user field). You can view the content of any of these files using cat
. For example, to view the anacron
file:
cat /etc/cron.d/anacron
Next, let's look at the directories for hourly, daily, weekly, and monthly jobs. We can list the contents of these directories using ls
.
Type the following commands one by one and press Enter after each:
ls /etc/cron.hourly/
ls /etc/cron.daily/
ls /etc/cron.weekly/
ls /etc/cron.monthly/
You might see various scripts or files listed in these directories. For example, /etc/cron.daily/
often contains scripts for tasks like updating the package list, cleaning temporary files, or rotating logs.
ls /etc/cron.daily/
apt-compat dpkg google-chrome man-db mlocate passwd update-notifier-common
These scripts are automatically executed by the cron system at the specified intervals (hourly, daily, weekly, monthly).
By examining the files in /etc/crontab
and the directories under /etc/cron.*
, you can get a comprehensive view of the automated tasks running on the system. This is crucial for system administration and troubleshooting.
You have now explored the main locations for viewing both user and system-wide cron jobs.
Click Continue to complete this lab.