CompTIA Linux+ XK0-005 – Unit 08 – System Maintenance Part 3

  • By
  • August 8, 2023
0 Comment

20. Demo – Backing Up with dd

Well, we’re going to look at using DD to do some of our backups. And what we need to know is the name of the device that some of our hard drives are mounted. So we need the Cat command to throw out some information about our different devices. And what I see here is I have the SDA One, that is one of our devices that’s available for me to use, and SDA Five, which is one that I use to create a swap file on. So it’s got some information as well. What we’re going to do is we’re going to do a backup of something that would normally not be our choice. I’m going to back up the SDA One drive and put it into my home directory, which unfortunately is on the SDA One drive.

Normally you would be backing this up to some other type of media tape or CD or DVD or something else. But due to limitations of what we have, we’re going to give that a shot and see what happens. So this is something that has to be done with the permissions of the route. So we’re going to use DD and the input file is going to be the device, the SDA One and the outbound file is going to be, as I said before, my home directory slash the name of it MBR dot DD. The block size is going to be 512 and the count is going to be equal to one. And I’m going to hit the enter and we’re going to wait for that stuff to happen. Let me put in the password and well, that seems to be pretty quick and straightforward.

Let’s do an LS now of our directory and there is our MBR dot DD. Now the good news was, because I kept the count to one as far as the the size, I didn’t take the entire contents of, of that drive. So I basically took that one block, that one block of size 512 had. I redone that same command with a count of 1000. The bad news is when you’re hitting the number keypad, you sometimes want to make sure you have the numb lock button so you don’t get those funny little characters like you just saw. Anyway, if I tried that and put that in there, then you would see a different size because it’s getting more of the information.

But like I said, I could possibly corrupt things if I’m not careful in the fact that I’m copying from the drive and putting it on the same drive that I’m copying. But that’s just how easy the DD is. You just need the input file, the output file, which includes the path of where it’s going to go, block size, the count of what you’re going to grab, basically how many of those blocks and be done with it. Now you do need to know the geometry of your drive to be able to get gather all of the information. But as I said before, one of the nice things about that particular program is it does a true sectorbysector copy.

21. Topic B: Scheduling Tasks

Alright? One of the things we like to see as an administrator is how can I reduce the amount of work I need to do? The easy way is hire somebody to do it for you. But in lieu of that, which would be great as well, is scheduling tasks. And so that’s what we’re going to do. We’re going to talk about how we can schedule a task as a one time task or as an ongoing type of a task to get rid of the daily maintenance, daily mundane tasks that need to be done so that we don’t have to actually stop what we’re doing and say, oh, I forgot. I have to run this program. All right, so we’re going to look at the options we have for setting that up.

22. Scheduling Commands

Now, there are two general commands that you’re going to use to schedule any type of task. The once only is a command called at, and you’ll like at. It’s pretty straightforward at this date, and this time do this job. And then there’s cron. Now, Cron is well known as a popular Unix Linux command. That is a scheduling command that allows you to put in repeated schedules for whatever activity you want to do. We often call these activities jobs, tasks, job, whatever you want to do. You generally hear people talk about looking at the job report to see if whatever they’ve scheduled has actually ran, if it ran successfully, or whatever else. Anyway, those are the two general commands, at and Cron.

23. The at Command

Now, when you use the at command, it is a one time only and you can ask it to even do things like email the results or to log what it does. The time notations are pretty straightforward. You can say at like 10:30 p. m. At midnight at tomorrow at now, plus two days, saying two days from today, or the most obvious at 430 on this day eight, do this job that is straightforward. Now, I like to tell people at is fun. At would be one of these things where you say, okay, look, my friend’s on call. I know that he plans on going out on the lake on the boat, even though he’s on call. That kind of makes me jealous.

So I’m going to schedule a job at noon on Saturday when he’s out on the lake. Okay, don’t really do that. That was just a joke. You’ll get in trouble. But the idea would be to sabotage the system so he has to come back in. Hopefully he got the joke. Anyway, you can do these schedule these jobs for these times we call maintenance windows. So if you want to schedule a backup, you could do a onetime backup by using this command at a time that is reasonable. You know, 02:00 a. m. 03:00 A. m. Whenever you think there will be very few people on the server so you don’t interrupt their work.

24. Demo – Scheduling Commands with at

All right, we are going to execute a command at a scheduled time with the at command. But before we do, we need to know what the current date is and time so we can schedule our command command. So there’s our command, our time, it’s 1159. And what I’m going to do is I’m going to create an at command and I’m going to say at now plus 1 minute. I don’t want to wait very long. And now I’m in this mode where I can issue the command LSL capital F. And we’ll do that for the current Roots directory. And we’re going to redirect it to a file called Testing TXT. And I’m going to enter, I’m going to type in Control D to exit that interactive, and it says it’s going to perform that at 11:00.

So we’re going to hit the date command and see when it hits that time. And if it hits that time for us pretty quickly, then we’ll do a cat command. Oh, wow. It says it’s 11:00 exactly now. Well, you know what? I’m just going to wait until it’s a couple of seconds passed and then we’re going to do a cat command to actually, I’m going to try the LS and see if if that command is there. There it is. There’s testing dot text. And so let’s do the cat Testing TXT. And there it is. It’s filled with all the stuff that we would expect to see. So there I created a command to run at a certain time. It runs only once and then it doesn’t run again.

25. The cron Command

Now, the Cron command, similar to at, is to schedule a task or a job. Now, we use the Cron command to be able to say, basically, I want these things done on a repeated schedule. Weekly, daily. Whenever you want it to run. You basically have to set up what and when you want something to run. Now, we’re going to see these stored under the Cron tabs folder, and you can see it under the etsy file cron tab. And look at the status of the daemon with the Cron D to see if it’s running. But it’s a straightforward set of commands that says, as I’ve said already, whenever I need this run, do this job again, it could be monthly, it could be daily. It’s just however you set it up on a frequency that makes sense for your business. Bye.

26. Sample crontab

So if we were to take a look at the Crontab file after you schedule these, basically it’s a text file, and it would tell you what your schedules are. You might see something that says as a descriptor first. You’ll see, the descriptor might say, run five minutes after midnight every day. OK, so then we go down and we read what it’s actually going to do and it tells you when it’s scheduled. It tells you what the job job is and what the results are, as far as if you’re doing a backup or whatever it is that job is. That’s what you’ll read as you’re going through the lines of the Cron tab. It’s just designed to show you what you’ve set up, what you’ve scheduled. Technically, you could probably sit there and edit this by yourself without using the Cron command to set up more of these jobs. Bye.

27. crontab run – parts Format

Now, when you read the Chron tab file, you’re going to have this long list that tells you all of the stuff you want to do. So if you were to read it from left to right, what you would see is basically the entry telling you the minutes, the hour, the day of the month, the month, the day of the week, and then finally the command that you want to run. That’s the frequency. You hear what I’ve said? It could be minutes, hours, which would be basically time. Day of the month would be a numerical on the first, on the 15th, on the 20th. The month would be numerically january, February, March, whatever it is. Day of the week, sunday through Friday, I think Sunday is zero. So that would make Saturday six.That would be seven days. Even though it sounds wrong, zero to six is seven, range of seven.

And then, like I said, the command. So an example might be for looking at this just depends on what you’re trying to run. If you want to run something every day, then you may not necessarily have a specific month and day, but the days of the week, sunday, Monday, Tuesday, Wednesday, everything you want to run for every day. If it’s something that runs once a day, then you probably would be specific about the times that it runs. Just again, it’s a matter of how you put together the command and the frequency and knowing how to read it. Should you be reading the Cron tabs? The Cron tabs file is your best way to know what’s been scheduled to run, especially if there are some jobs that you no longer need and you want to get rid of them.

28. Managing cron

So in managing your tasks that you schedule with Cron, you have to be able to know how to read the Cron tab file. Now, you can also control who is allowed to create these jobs and who is not by going in and configuring the Cron allow or the Cron deny files. Again, all of these are under the Etc. Or Etsy folder. Now, there are some machines, machines that are not on 24 hours a day, like laptops. And so it’s very difficult to run something like Cron when a machine could be turned off at the time the job is supposed to run.

So there’s another option, another command called Anacron that’s short for an Anachronistic Cron job. It’s great for the laptops that might be powered off, therefore not able to hit or follow a regular schedule. But we’ll when you turn this thing back on, if there’s something that was supposed to have run, but it’s past that time, then Anacron is going to go and say, oh, I got to run this job because I was turned off. And so it’s a great way of being able to schedule things for different types of environments where you’re not 24/7 with the power.

29. Demo – Scheduling a Job with cron

All right. Now we’re going to schedule some jobs with Cron and those are things that are going to occur all the time. So what I’m going to do is look at the current date and time. It’s kind of important because I have to schedule in the future something that’s going to run. And if I don’t know what the current time is now, I mean, it doesn’t mean I can’t make the schedule. It just means that you and I are going to sit there and watch for a long time, possibly waiting for something to run. So I’m going to hit the Cron tab and you can see that I have absolutely nothing in there as far as any scheduled jobs.

And I’m also in my favorite VI. Okay, so what we’re going to do is we’re going to type in a job that we are going to run. And what we’re going to do is of course fill it in as far as the job number and all this other kind of stuff. And we’re going to put it in based on our time that we just saw, in fact, just to verify our time. Because again, this is going to be one of the more important parts of what we do is to make sure that I get this time in the future. Coming up, it’s going to take me a couple of minutes to talk about it. So we’re going to try to shoot for about eleven seven, I suppose. So here I am back in my editing and what I’m going to do is I’m going to go in here and put in the information as far as the minutes.

So I think eleven eight is what I was looking at because it’s eleven four, the hour is eleven, the day of the month will be the 11th. The month itself is January and the day of the week is a Monday. And the command that I’m going to put in here is going to be to do the LS again, l capital F. And we’ll start at the, from the root directory I think is what we did on our at command. So we’ll root directory, redirect it to our dollar sign home and a file called Crontest TXT. Okay, so if all goes well, I’ve got the minutes, the hours, the day of the month, and everything else set up in there. And Control X takes me out and I’m going to say yes to modify what I have and hopefully that’s the right name of the file that I’m going to create the file name that I want to type in and that looks appropriate as well.

So with that information I’m going to hit enter. And I’ve got the new Chron tab set up in there. Okay? So now to look at it, I can do crontab l and see what I have set up for eleven, eight coming into that particular time to run that little command. And I’ll follow it up with a date command here to see that I have about a minute and a half to let that go on and do its job. Now, if I look right now and I try to do the Lslf, you can see that I don’t have a file here called Cron Tab, so it’s not available to me at the moment. And we’ll just have to keep waiting for that next little time for the eleven eight to occur. So after we see the eleven eight hit, we’re going to go take a look and see if the results of that file are there.

And then when we’re done, we’re going to delete that Cron tab file because we don’t need to keep doing that all of the time as we go through. So remember, Crontab L listed the jobs that you have. Crontab R would delete that file. And of course, looking at the date command, it’s still not quite there. Well, as much as they say, watching a pot will watch pot never boils. That’s how I feel. I couldn’t resist. I had to do the date command again, and I was just a bit early. I still had a couple more seconds there to let it go. I could be like that anxious little child waiting to do a certain event or activity or open a present. Ah, there we go, eleven eight. So, boy, with any luck, I can do my LS command and see a new file in there called the Cron Tab. And I’m looking through there.

Or cron test. There it is. I see it up at the top, Kontext TXT. So it gives me an idea that it ran. Let’s do a cat with the Crondest TXT file, and there’s the results of my output. Okay, so that was a scheduled job. It occurred and it would occur tomorrow. But I’m going to type in if I do Crontab L, you can see that it was one that was scheduled again and could be recurring. But I’m going to Crontab R, and now Crontab L again to show you that that job is gone, at least for that particular user, which is also important. All right, so that was scheduling jobs with Cron basically is what we would call it, or often, as we said, and I know some people like it or not, but we often call it Cron scheduling or creating a Cron job because you would look up the list of jobs that are running.

Comments
* The most recent comment are at the top

Interesting posts

The Growing Demand for IT Certifications in the Fintech Industry

The fintech industry is experiencing an unprecedented boom, driven by the relentless pace of technological innovation and the increasing integration of financial services with digital platforms. As the lines between finance and technology blur, the need for highly skilled professionals who can navigate both worlds is greater than ever. One of the most effective ways… Read More »

CompTIA Security+ vs. CEH: Entry-Level Cybersecurity Certifications Compared

In today’s digital world, cybersecurity is no longer just a technical concern; it’s a critical business priority. With cyber threats evolving rapidly, organizations of all sizes are seeking skilled professionals to protect their digital assets. For those looking to break into the cybersecurity field, earning a certification is a great way to validate your skills… Read More »

The Evolving Role of ITIL: What’s New in ITIL 4 Managing Professional Transition Exam?

If you’ve been in the IT service management (ITSM) world for a while, you’ve probably heard of ITIL – the framework that’s been guiding IT professionals in delivering high-quality services for decades. The Information Technology Infrastructure Library (ITIL) has evolved significantly over the years, and its latest iteration, ITIL 4, marks a substantial shift in… Read More »

SASE and Zero Trust: How New Security Architectures are Shaping Cisco’s CyberOps Certification

As cybersecurity threats become increasingly sophisticated and pervasive, traditional security models are proving inadequate for today’s complex digital environments. To address these challenges, modern security frameworks such as SASE (Secure Access Service Edge) and Zero Trust are revolutionizing how organizations protect their networks and data. Recognizing the shift towards these advanced security architectures, Cisco has… Read More »

CompTIA’s CASP+ (CAS-004) Gets Tougher: What’s New in Advanced Security Practitioner Certification?

The cybersecurity landscape is constantly evolving, and with it, the certifications that validate the expertise of security professionals must adapt to address new challenges and technologies. CompTIA’s CASP+ (CompTIA Advanced Security Practitioner) certification has long been a hallmark of advanced knowledge in cybersecurity, distinguishing those who are capable of designing, implementing, and managing enterprise-level security… Read More »

Azure DevOps Engineer Expert Certification: What’s Changed in the New AZ-400 Exam Blueprint?

The cloud landscape is evolving at a breakneck pace, and with it, the certifications that validate an IT professional’s skills. One such certification is the Microsoft Certified: DevOps Engineer Expert, which is validated through the AZ-400 exam. This exam has undergone significant changes to reflect the latest trends, tools, and methodologies in the DevOps world.… Read More »

img