In this demonstration,
we're going to walk through
how to schedule tasks.
We're going to perform this by
two different methods.
We're going to use the "at" command,
which will execute a one-time function or command
in the future one time.
Then we're going to go over cron jobs,
using the "crontab" command.
Cron is when we want to schedule tasks
so they occur repeatedly in the future.
And this, we're going to schedule all of our
mainest jobs to run automatically over and over again.
So the first thing we want to check out is the "at" command,
which I'm going to create a simple file.
OK, so we're going to add this to our directory.
Now we're going to run a test
to execute in the future one time.
And that's going to be: remove this touch file
that we just created, file A.
So let's make sure it's in there.
OK, we see file A.
About six down.
Now we're going to run a command,
and we want to execute two minutes from now.
So we're going to do: "at now + 2 minutes".
And the interacting prompt is going to pop up.
And here, all we do is input the commands
that we want to run.
We're going to remove,
force,
and do Ctrl + D.
OK
Now we're going to look at the queue, "atq".
Now we see a schedule
to execute in the next two minutes.
OK. Time has passed.
Now let's check the queue.
Alright, that's the first indication that
the command went through.
Now let's look through our list.
I'm going to "grep" for the file A,
just to be clear it's out there.
Alright.
Alright. We're going to see now that file A
is no longer there.
So again, we used the "at" to execute a function or command
one time in the future.
In this next scenario, we're going to go through
and use the "crontab" command
to schedule an email reminder
at a specific time in the future.
Now the way the cron command is broken up,
once you're editing the actual file,
the first five fields are just going to reference
different time periods.
So the first field is going to reference minutes.
The second field is going to represent hours.
Next is going to be the day of the month.
Fourth is going to be the month.
And the fifth field is going to represent a day of the week,
if you're going to make it a repetitive task.
For example: "1" would equal Monday,
so that means every Monday on this time,
or maybe even a future date.
Typically we're just going to use the
minutes, hours and day.
Or if you want to do one specific day,
you're going to use
minutes, hours, day, and day of the month.
In this example, we're just going to use
a specific hour in the future.
And if it doesn't have any day tied to it,
it's assumed it's going to occur daily.
So we're going to set an email to be sent to us
every day at a certain time.
So let's try that first.
"sudo crontab"
To the user.
I'll use myself.
And "e" means edit.
Alright. So we're going to do this
for five minutes in the future.
Or, four minutes in the future.
Let's make it 17:20, if we look at my clock.
So we'll put "20" here for the minutes.
"17".
Everything has to be in a 24-hour format.
We'll put "bin/echo".
Let's do "Please fill in your time sheet."
The last field is going to be
a path to the command that you're trying to execute.
So an example:
we're trying to execute a simple "echo" command.
And it's going to email this information to us.
OK, click.
Right click.
Alright.
Alright, let's check that mail really quick.
OK, we see July 4th today.
OK. We see that it was successfully received
at 17:20 and one second.
Alright, that sums that up.
We went through how to use the "at" command
for a future transaction.
We also went over how to use a "crontab", edit that.
We sent an email to ourself in the future.
And right now it's set for a recurring task
that happens once a day.
Thank you for sticking with this walkthrough,
and I'll see you in the next lesson.