[No audio]
Hi everyone. In our previous lecture, we
have learned how we could schedule jobs
or tasks to cronjob or addjob. And as we
all know, that addjob is used for ad hoc
task for one time use. And if you want
to schedule jobs or specially repetitive
job, you would use cronjob or crontab.
Now, I want to cover some
additional things about cronjob. By
default, there are four different types
of cronjob, that is set for you, that is
like out of the box, that operating
system the Linux operating system offers
you, and those jobs are hourly job, daily
jobs, weekly, and monthly. So anything,
any task that you want to run hourly
basis, or weekly, or monthly basis, you
could do it two ways. One, you could do
through the crontab minus e, and
specify it over there. Or you could
simply have the script added inside of
the hourly, daily, weekly, monthly
directories. Those directories are in /etc/cron.,
hourly, dot daily, weekly
or monthly. So you go into each of these
directories, and you put in your script
that will run every hour, or depending
on how often do you want to run. And
then you don't have to do anything about
the crontab or anything. Then the cron
dot daily or hourly depending on which
one you pick will do the job. Now the
timing of each are set in /etc/anacrontab
When you do cat, you will see
that anacrontab has the timing of
when the daily, weekly, and monthly job
will run, except the hourly one. The
hourly one is defined, the what time it
runs it is defined in /etc/cron.d/0hourly.
That's the file that
defines when the hourly runs. So let me
get into my Linux machine, and we'll see
how these jobs are set up in each
directory. So I have my terminal open, I
am logged in as a root. Now first thing
I want you to do is go to cd /etc.
In here, you will do ls minus l
cron.*, and you run, when you
enter you will see, it will grep, it will
grep everything that starts with cron. So
it's getting cron.deny, cron hourly,
sorry, right here. The directory we have
is cron.monthly, cron.hourly, but the
right way to show you is I will do is ls
minus l grep for cron. So this way, you
will see the directories that I want to
go work for. So you see right here the
cron.daily, cron.hourly, monthly,
and weekly. And this is the crontab,
the actual tab where you go in and
specify manually if you don't want to go
into each daily, hourly, or weekly. So
let's say if I go into cd cron.daily,
and which directory I am in, I'm an /etc/cron.daily
do ls minus l, you will
see it has three different cron, or the
tasks, or the scripts that run daily.
And these are the actual scripts that
were run daily. If you have a script
that you want to run daily, once a day,
then you, all you have to do is put your
script, move it in this directory, which
is cron.daily. If you want to run your
script, hourly, then you go into one
step back and you go into cron.hourly,
and then you add that into this
directory. Your script moved that script
into this directory. Similarly, if you
want it to add or run your script every
month, then you could do cron.monthly.
Go into this directory and do
ls minus l. You'll see there is nothing
right now in that directory. So all you
have to do is move your script to this
directory and by default, it will run
every month. Now question is how or
when does the monthly runs or when daily
runs. So that is specified in when you
do cat /etc/anacrontab and hit
enter, and you will see the timings that
are set right here. So 1 5 cron.daily,
that's the daily time it will run.
7 25, it's the weekly. See period in
days, seven, seven day, delay in minutes,
delays in delay in minute, and job-identifier,
and command, this is a
command it will run. So this is the
timing that it is telling you. These are
the timing that it will run your daily,
weekly or monthly jobs. Now what about
the hourly? The hourly is not specified
here. To view the hourly scheduled time
you have to do cat /etc/cron.d/0hourly,
and you will see 0hourly is
scheduled to run at 01, which is 12:01.
At midnight, every night, it runs.
Anything that is specified in the
hourly, sorry, not midnight, that would
be daily. It is scheduled to run every
one minute after the hour. So it will
run at 12:01, 1:01, 2:01, 3:01. So every, one past
minute, every hour if you define your
script into cron.hourly. So anyway,
this is what I wanted to cover. If you
wanted to go over the cron details and
you don't want to specify cron dot,
crontab minus e. You don't want to write
down into this cron, then you don't have
to, you could simply go into each
individual directory and all you have to
do is put your script in that directory
and let these directories or let these
jobs run as they are scheduled to run.
[No audio]