So Cron is an old UNIX scheduling option.
It has been around since the 1980s already.
And that is why it's still in RHEL 10,
because of backward compatibility.
Cron uses Cron-D. That's a daemon
that checks its configuration to run Cron jobs periodically.
And still on RHEL 10, Cron-D is enabled as a system
D service by default. But most services that need scheduling
are scheduled through system D timers.
Nevertheless, you should know how it works.
So the Cron-D process checks its configuration every minute.
An ETC Cron tab is the main managed configuration file.
This is a file that you shouldn't use.
You should put Cron jobs in the ETC Cron.D file.
Then there is also ETC Cron.Hourly, Daily, Weekly,
and Monthly.
And these can be used as drop-ins for scripts
that need to be scheduled on a regular basis.
The difference between the Cron.Hourly, et cetera,
and the Cron.D is that Cron.D files
need to have a Cron syntax.
And in Cron.Hourly, you just need to dump a script.
Do make sure that these scripts have the execute bit set.
And another way to create Cron jobs
is to use a specific Cron jobs.
Use Cron tab minus E to enter the Cron editor
and configure your Cron job for a user.
Well, if you want to do that, Cron tab minus E
is opening the editor.
Please also use minus U username.
Now, when you work with Cron, you need a time specification.
And the time specification is specified
in minute, hour, day of month, month, and day of week.
So you will see something like 0, star, star, December 1-5,
which will run a Cron job every Monday through Friday
on minute 0 of every hour in December.
The ETC Cron tab file has a syntax example with annotation.
So check it if you're not sure about what you are doing.
But don't forget, do not edit ETC Cron tab.
Put drop-in files in ETC Cron.D instead.
In general, on modern Linux, you should never
edit these main configuration files.
They always work with drop-in files,
as we have seen so many cases already.
Cron is helped by Anacron.
Anacron is the service behind Cron
that ensures that jobs are executed on a regular basis,
but not a specific time.
And Anacron specifically takes care
of running the jobs in ETC Cron.Hourly, Daily, Weekly,
and Monthly.
There is configuration in ETC Anacron tab.
My advice is don't change anything.
In Anacron, use systemd timers instead.
Now, let me demonstrate how you can use Cron.
First, I'd like to show you LS on ETC Cron star slash star.
So what do we see?
Well, we see that there is not a lot of Cron directories
anymore.
We have Cron.D, and we have Cron.Hourly.
If you would do this on RHEL 8, for instance,
you would see a lot of files that are automatically
executed by Cron.
As I mentioned before, this is not used anymore,
because nowadays we have systemd timers.
But one thing that you might find in Cron
is the user-specific Cron job.
So let me use Cron tab minus E minus U, Linda.
And there, I'm going to create a Cron job for you.
So Linda, on every minute of every hour
of every day of the month of every month
of every day of the week, we are
going to run a logger greetings from Linda.
I'm using uppercase so that we can
recognize it in an easier way.
This is not very pretty, but we want
to verify that it works, right?
The logger command writes to the default syslog mechanism.
And I just quit the Cron tab editor.
And you can see that Cron tab is installing the new Cron tab.
Now I need to wait for the top of the minute.
And from now on, that takes about 48 seconds.
So now the 45 seconds are over.
Let me use journalctl, because that is showing the default
logging interface, uppercase G, to go all the way down.
And you see it, greetings from Linda.
Yay, it worked.
So I'm not sure if I want to do this every single minute.
So I'm going to use Cron tab minus E minus U, Linda again,
and delete the line.
You got the idea, right?