Hello and welcome to this video on Oracle Linux 8.
In this video, we will cover Oracle Linux 8's cron utility.
For our objectives today, after viewing this video, you should be able to:
Describe the available automated task utilities
Configure cron jobs
Describe cron directories and files
And lastly you will be able to implement the crontab utility
Oracle Linux can run programs automatically.
Programs are also referred to as tasks or jobs.
Utilities to automate these tasks or jobs include cron, anacron, at, and batch.
Use the cron and anacron utilities to schedule jobs to run on certain days or times.
You can use cron to run jobs as often as every minute.
A cron job will not run if the system is down during the time that the job was scheduled
to run.
Use the anacron utility to run a job once a day.
If the system is down when the anacron job is scheduled to run, the anacron job will
run when the system comes back up.
Therefore, you can use anacron to run cron jobs that failed to run because the system
was down.
The crond daemon executes scheduled tasks.
It searches /var/spool/cron for crontab files for individual users, /etc/anacrontab, and
the files in the /etc/cron.d directory.
It checks each command to see whether it should be run in the current minute.
When a task is scheduled for execution, crond executes it as the user who owns the file
describing the task.
cron jobs are defined in the /etc/crontab configuration file.
Besides root, users can also have cron jobs.
cron jobs are specified in the following format:
minute hour day month day-of-week command
A minute is from 0 to 59.
An hour is from 0 to 23.
A day is from 1 to 31 which must be a valid day for the specified month
A month is from 1 to 12 and you can also use Jan, Feb, Mar, and so on.
The day-of-week is either 0 or Sun, 1 or Mon, 2 or Tue, 3 or Wed, 4 or Thu, 5 or Fri, 6
or Sat, or 7 or Sun
And then finally the command which is the program or script to execute
Also other special characters can be used.
An asterisk represents all valid values.
A hyphen between integers specifies a range of integers.
A comma is used between a list of values.
A forward slash specifies step values.
The /etc/cron.d directory contains files that have the same syntax as the /etc/crontab file.
Only root has permission to create and modify files in this directory.
Also in /etc are cron directories named:
cron.hourly
cron.daily
cron.weekly
cron.monthly
Scripts in these directories run hourly, daily, weekly, or monthly, depending on the name
of the directory.
The /etc/cron.allow and /etc/cron.deny files are used to restrict access to cron.
These files are checked each time a user tries to add or delete a cron job.
You can specify users, each user on a separate line, that can use cron in the cron.allow
file.
Conversely, you can specify users, each user on a separate line, that cannot use cron in
the cron.deny file.
The cron.deny file is only checked if the cron.allow file does not exist.
Only the root user can use cron if neither file exists.
Users other than root can configure cron tasks by using the crontab utility.
All user-defined crontabs are stored in the /var/spool/cron directory and are executed
by using the usernames of the users that created them.
To create or edit a crontab as a user, log in as that user and enter the crontab -e command.
The file uses the same format as /etc/crontab with one exception: do not specify a user.
When the changes to the crontab are saved, the crontab is stored according to username
and written to the /var/spool/cron/ file.
To list the contents of your own personal crontab file, use the crontab -l command.
Let's create a crontab for the oracle user.
Use the crontab -l command to list the contents of oracle's crontab file.
As you can see, no crontab exists for the oracle user.
Use the ls command to view the contents of the /var/spool/cron directory.
As you can see, a cron file does not exist for the oracle user.
Use the crontab -e command to create a crontab job that echoes a simple message every minute.
After a minute, the cron job runs and fires off an email to the oracle user
Use the ls command to view the contents of the /var/spool/cron directory again.
Now there is a file for the oracle user in the /var/spool/cron directory.
Enter mail to view the output from cron jobs which is sent to the user's mailbox.
Enter 1 to view the first mail message.
As you can see, the cron job ran successfully.
Enter q to quit.
Use the cat command to view the contents of the cron job in the /var/spool/cron directory.
Now use the crontab -r command to remove the crontab.
Once again, use the crontab -l command to list the contents of oracle's crontab file.
And lastly, use the ls command to view the contents of the /var/spool/cron directory.
As you can see, the oracle file has been removed from this directory.
After watching this video, you should now be able to:
Describe the available automated task utilities
Configure cron jobs
Describe cron directories and files
And lastly you will be able to implement the crontab utility
Oracle provides an extensive number of resources which you can use to learn more about this
subject and others.
Look for additional videos on Oracle Linux 8 and other topics using the links shown.
This concludes the video.
Thank you for watching.