Okay, in this video I want to show you what's going on
with Cron. So to start with sudo systemctl status on crond service.
Sometimes it's crony, sometimes it's cron, depending on your distribution.
But here we can see that cron is actually running.
Now this cron service has its main configuration file.
If I use sudo cat on etc crontab then we can see what it is like.
Historically you would put everything in here. That's not how we do it nowadays anymore. But I
like it because it has an explanation of the times. So it has five positions to indicate
the minute, the hour, the day of the month, the month and the day of the week.
And based on that I can create my own crontab.
And in order to do so, I'm going to use sudo crontab E
for edit, U for lynda. I want to create a crontab for user
lynda where I'm going to set star star star star star.
Oh my goodness. Really? Yeah, I want to do it every minute because I want to show you that it works.
And I am going to use logger.
Greetings from Linda.
Now what did we just do? Well, I just created a new cront app for user
Lynda, E started the editor and U is doing it for a specific user. That's what
I like about crontab. You can easily create tasks that will be executed by specific users.
Now normally it will do so on top of the minute. That's why I've done every minute. In real life you don't want to do it every minute.
But now I want to make sure that we can see a result.
So are we already on the top of the minute? Well, seven
more seconds of waiting and then we should see the result.
So I'm going to use sudo journal ctl.
Now, what is journal CTL showing? Well, journal CTL should show on top of the minute and oh
boy, a lot of things have happened on top of the minute. But that includes greetings from Linda.
Journalctl is the easiest way to get more information out of the
systemd journal. That's a topic we'll talk about later by the way.
So this is one thing that you can do with cron. Now, depending
on your distribution, you might have Kron automatically pickup configuration files if that
is the case. Well, you are going to find out by using lsetccronestar.
And what you would be looking for is if you have anything, any directories and any files
in there here on Centos we don't. But let's check out how it works on Ubuntu.
So here I'm on Ubuntu and I'm using LS on Etc.
Cron and there you can see that there's a couple of subdirectories. So there is the
Etc Cron D which has cron jobs that will be picked up by the cron daemon.
There is Etc. Cron daily, weekly, monthly, which is cron jobs
that will be executed at a daily, weekly and monthly basis.
Like mandb for instance.
So this Ubuntu system is running mandb every day now everything in the cron
daily, weekly or monthly directories is a shell script that will be picked up
automatically and stuff in etc. Cron D should have regular cron syntax.
So when I would check etc. Cron D
systat we can see what it is doing.
I like this command because it has a little bit more complex syntax.
What do you think of this for 5,55,10 that means starting at minute 5
until minute 55 of every hour of every day of the month, in every
month and every day of the week it will run this command.
We also see a second one, 5923 which means every day
at hour 23, minute 59 it will run this other command.
That is what these cron files may look like now. You should know that
cron is from the past and distributions are moving on to systemd timers nowadays.