LPI 102-400 – Automate system administration tasks by scheduling jobs
Hello, students, and welcome! In this section, we are going to cover automate tasks by scheduling jobs in Linux. Our objective in this section is to learn how to use Cron or Anacreon to run jobs at regular intervals and use AT to run jobs at specific times.
The knowledge areas that we’re going to cover are how to manage Cron and Et jobs, how to configure user access to Cron and Et services, and how to configure Anacreon. So Cron is a time-based job scheduler. It is configured to run commands at given times or intervals. Each user has a Cron table, which defines what to execute and at what interval. The crontab command is used to create, modify, and view cron jobs. Configuration files and directories in Cron are controlled by a set of files called Cron tabs. There’s the master file in the Etsy cron tab, along with cron tab files for the users in earspool cron. In this directory, the files are given the same name as a user’s name: the techy. The crontab file automatically executes items in several subdirectories at regular intervals. The scripts placed in various directories marked with an asterisk (slashEtsycron) are run as part of the time interval given in the next section.
All the scripts in these directories are run with root privilege. And here’s the hourly, daily, weekly, and monthly configuration. We have used some examples here. So if you are running a Cron job hourly, that’s going to be the first minute of every hour. If it’s going to be croned daily, we can specify a time when it must run. We have used the example of three or 5:00 a.m. to 10:55 p.m. Each day. Then we can use it to run weekly jobs between 3:25 a.m. And at 11:10 p.m. After seven days since the last execution, and the same way monthly between say, 03:45 a.m. and 11:30 p.m. After a month since the last execution So setting up a user level The Cron tab is somewhat different. The files in earspool-chron are not edited directly. Instead, a programme called ChronTabis was used to manipulate them. The syntax of the cron tab command is cron tab, some options, and then the file name chron tab, options, and chron tab, hostname, and these are the options that are available for the user to define the user.
E for editing user chron tab, L to list user chron tab, R to delete user chron tab, and so on. S represents the Selina context, and X represents the debugging mask. Now, how do I edit a Cron. Tap file? The best way to edit a Cron tab is by using the command cron tap space lowercase E. Another way of doing it is to send a message to the user whose cron you want to change. So crontab it and point it to the file name, copy the crontab to a file, VI the file, make the necessary changes to the file, and then crontab the file. This creates a new case.
In my personal opinion, using Crontab is much simpler than going this route. But this is just to let you know that it is available. Each Cron command has five time and date fields followed by a username, which is optional. And if this is a system Cron tab file, it’ll be followed by a command. Commands are executed when the time specified in the time date fields matches the current time. So the time is one minute, going from zero to 59. These are the log values. Our 0 to 23 scale date of the month. The months are numbered from 0 to 31. The month is zero through twelve. Our names and day of the week are zero through seventy. or Sunday is seven. Alternatively, use the names themselves, such as Sunday, Monday, and Tuesday.
Hello students. In this lecture, we are going to give you an example. A field in the Cron statement can also be expressed by an asterisk, as you can see in this example here. So starting with the first one, the minute starts here. So there are no minutes. So that’s going to be a whole hour. It’s not going to be a certain hour and minutes, but just a whole hour. So every hour and every day of the month That is what the asterisk indicates here. Every day of the month, every month of the year, from one to twelve So the asterisk here means every month of the year, every day of the week, and again, the day starts from zero through six. Sunday is zero or seven. And you can write Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday.
Or you can have zero through six. And then, once you’re done with this part of the statement, you’ve got to have a username, which is optional. The command to be executed could then be a script or a Linux command with the full path so that the cron job knows exactly how to start the job. And we’ll learn some real-world examples on the real system so you can see it in action. Okay, now we’re going to use an example. So we start off with confab e.
And then we’re going to insert 50 and then home. Oracle scans ASM hen home. Osos what is this script doing? Or what is this cron job doing? So what is it doing every five minutes, because remember, this is a minute field? Every 5 minutes and every hour. That means constantly—every five minutes, every day of the month, every month of the year, and every day of the week—we are running the script, which resides in home Oracle, and this is the name of the script. And if you notice that the username is optional, we haven’t used a username in this. And you just save it like you would save a typical VI file. And it’s saved; if you want to change it, go to the chron tab; it’s there.
Hello students. In this lecture, we’re going to talk about the service Cron D that runs on the Linux system in order for Cron to work. So if you want to check the system, or if your chronicle is even running the system, CTL would be the way to go in the latest versions of pretty much any Linux flavor. As a result, System CTL, status chronic and, as you can see currently on my system, it’s not running. So I’m going to start it. System CTL, start Crond, and now check the status; you can see that it is active, and you can also stop it. So go back on this command and run a stop.
And now check the status again; it’s stopped again. And another way to manipulate this command is to start Chron and then stop and restart it. Let’s check the status first. It is currently active; I want to stop and restart it, and let’s come over here and restart it. So let’s see the status now. It’s been stopped and restarted. So this is how you manipulate the Cron daemon by using SystemCtl. Next, we’re going to discuss the command. The at command schedules the command to be run once at a particular time that you normally have permission to run. The command can be anything from a simple reminder message to a complex script. Begin by running at the command prompt and passing it the scheduled time at the option. It then places you at a special prompt where you can type in the command or series of commands to be run at the scheduled time. And when you’re done, press CTRL-D on a newline, and your command will be placed in the queue. So let’s take a look at an example. Okay, now we’re going to run an example. So let’s do this.
At, of course, you begin the command with 80, and then the time, say 730 on Friday. It returns us to the prompt, and you can type in, echo it, or type whatever you want. Marathon day is tomorrow. It’s just like a reminder for myself, and I go to the next line, and then I say Control D, and it puts it in the queue. Assume I want to see what’s in my queue and I just type in At Q and I, we currently have two reminders, one for Tuesday and one for Friday. And keep in mind that it doesn’t have to be a reminder of any kind. It could be anything. I could have said something like, “Let’s change the time on this and the date to Saturday, and the time is 06:30 a.m.” And this is a new one-time command that I’d like to run, which we’ll call Etsy Tmptestsh. I suppose I’ve written a shell script called Test Sh that lives in Tim; that’s the full path to it. I wanted to run at 6:30 a.m. On Saturday, do a CTRL-D and look at ATQ again. And now it’s going to show us three schedules that we have set up specifically. These are going to only run one time. Remember, this is different from Cron. Cron runs continuously until you stop it or clear it, but it is only going to run one time. And that’s the difference between the two Crons and 18.
Hello, students. In this lecture, we’re going to talk about the Cron Allow file. If this file exists, then you must be listed therein in order to be allowed to use this command. If the Cron Allow file does not exist but the Cron Deny file does, then you must not be listed in the Cron Deny file in order to use this command. Okay, so let’s use an example. At cmon allow, we’re going to say touch. Our file is created to allow some users to use the Cron tab. We must append the user names to the file and ensure one user per line, allowing users test one and test two to use the Cron tab. And here’s how we’re going to do it:
Hello, students. In this lecture, we’re going to talk about Anacron. Anacron, as opposed to Cron, is different in the sense that once a job is scheduled through Anacron, it is going to run. So even if the system is down, So, if you have a laptop and you schedule an Anacron job, and the laptop is powered off right now, and the time for that scheduled job has passed, whenever you turn that laptop back on, even if it’s 2 or 3 hours later, that backup or the job that didn’t happen on time will run now. So it will eventually run. That is a feature of Anacron.
So let’s take a look at it. The most commonly used files in Anacron are etsy and the Cron tab. So, if you look at the Etsy Anacron tab, you’ll notice these entries. These are there by default, and you have Cron daily, Cron weekly, and Cron monthly in there already. For this facility, the default spool directory is varspool Anacron, LS l VAR spool Anacron. And they typically store the information on when this particular job was last executed. So if I cat VARspool Anacron every day, it’ll have an ID or the date it was last executed in there. So 10/20/2018, which is today, Let’s see an example of the Anacron tab file. So we’re going to be on the Etsy Anacron tab, and this is our existing file; shift g to go to the bottom of the file, and O to open up a new line. And I’m going to type it in here every day. So this task is going to run daily, 15 minutes after the system has been powered on with Rsync, because I want the system to sync daily. And the default shell I want to run is bin Bash. And then the actual command that I want to run home Let’s bash. And tStephen has a script directory with a script called backup r sync dot sh in it.
That’s the name of the script. So every time the system is booted up, it will give the system about 15 minutes, and then it’ll run this, which of course you can change to five minutes, ten minutes, an hour, or whatever you like, and it’s saved. Now, run Anacron capital T to ensure that there are no syntax errors in your Anacronfile; it returned nothing. That means I have no syntax errors in my task. So normally, Anacon runs background jobs and doesn’t display anything on the screen. But sometimes you need to see the output on the screen itself, and it is possible by using a D switch. So if you type Anna Cron D, it will tell you what job is about to start. Like in my case, in 43 minutes, a job will be completed. If you want to force the execution of an Anacron job, you can use Anacron F. In my case, since I don’t have an actual script for Stephen that’s going to run, it’s not going to do anything and is probably going to error out, but this is how you force it to run. Zena Khan started this time and is doing all the other stuff, but the one for Stephen is not going to run because, as I said, I don’t have a script for him.
Popular posts
Recent Posts