- [Instructor] There are two different types
of scheduled jobs.
One time jobs and recurring jobs.
For one time jobs we use a service called at.
The at service runs at jobs at a certain time.
Or in the case of a batch job,
when the CPU load average drops below 0.8.
The syntax for at is at, space,
and then the time format.
At supports a wide variety of time formats
including simple 12 and 24 hour clock times,
like 4:25 am, or 16:45.
It also supports general terms like
midnight, noon, tomorrow, and now,
plus a specified number of minutes, hours or days.
It even supports teatime which is apparently at 4 pm.
If we don't want to schedule one time job today,
we can specify a time and date.
The time format always has to come before the date.
The at services is usually installed by default.
Let's be sure by installing it using Yum,
and if there's a newer version Yum will update it.
Type into a terminal sudo Space,
yum Space, install Space -y, Space at,
and hit Enter.
Type in your password and hit Enter again.
We'll also want to ensure the service
is running and survives a reboot.
Type in sudo Space, systemctl,
Space start, Space atd and hit Enter.
To ensure the service starts on boot,
type in sudo Space systemctl,
Space enable, Space atd and hit Enter.
To create an at job that will run
in five minutes we type in at,
Space now, Space +, 5min and hit Enter.
This will give us a prompt where we
can type in Linux commands to run.
Let's type in mkdir, Space
~/Documents with a capital D,
.bak and hit Enter.
Now let's type in rsync,
Space -a, Space ~/Documents with a capital D,
/ Space ~/Documents with a capital D,
.bak.
This will use the rsync command to back up
our documents directory.
Ensure that you've used ~/Documents
with a capital D, /
and that that trailing slash is there.
Hit Enter and press ctrl+d to save it.
To verify our at jobs,
type in atq and hit Enter.
Starting in the left hand column,
we see the at job number,
in this case number one.
In the second column the time and date,
then the que letter and lastly the user name.
We can view the at file itself using
at-c followed by the at job number.
Type in at Space -c and the at job number
which is number one in my case.
This shows the contents of the at job
including the shell environment.
The commands we typed in will appear at the bottom.
If you'd like to cancel an at job you can use
the atrm command.
Type in atrm Space, followed by the at job number
which in my case is number one and hit Enter.
Verify with atq by typing in atq.
The at service also allows us to create batch jobs.
The difference between an at job and a batch job,
is that the at job runs at a specified time.
Batch jobs run when the system load average
drops below 0.8 ensuring they only get run,
when the system isn't busy.
To create a batch job type in batch,
and hit Enter.
Now insert the commands you wish to run.
For this example we'll do something simple.
Type in touch, space ~/batchfile.txt
and hit Enter.
Press cntrl+d and type in atq and hit Enter again.
If our computer is busy the batch file won't run.
If the system load average drops below 0.8,
the batch file will run.
Atq shows batch jobs.
If it doesn't show up then that means
the batch job already ran.
To verify this we can check to see if the file
was created using ls.
Type in ls, Space -l, Space,
~/batchfile.txt and hit Enter.
If the file exists that means the file ran.