Linux Bash Shell Scripting with Real Life Examples | Imran Afzal | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Linux Bash Shell Scripting with Real Life Examples

teacher avatar Imran Afzal, Systems Manager / Instructor

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

70 Lessons (11h 36m)
    • 1. Syllabus Overview

      6:02
    • 2. Welcome to Lab Setup

      3:24
    • 3. What is VirtualBox

      1:52
    • 4. Download and Install VirtualBox

      3:32
    • 5. Creating First Virtual Machine

      5:20
    • 6. Linux CentOS Installation

      23:24
    • 7. Welcome to Shell Scripting Basics

      1:54
    • 8. What is Kernel

      2:25
    • 9. What is Shell

      3:07
    • 10. What is Shell Scripting

      2:49
    • 11. Type of Shells

      6:49
    • 12. Starting a Shell

      11:02
    • 13. How to Run a Shell Script

      5:32
    • 14. Welcome to Scripting Standards

      2:10
    • 15. Scripts Naming Convention

      4:55
    • 16. Script File Permissions

      4:40
    • 17. Shell Script Format

      9:54
    • 18. Sequence of Script Execution

      1:45
    • 19. Welcome to Basic Shell Scripting

      3:44
    • 20. Create your first script Hello World

      10:00
    • 21. Run Basic Tasks Script

      9:50
    • 22. Run Basic Administration Tasks

      9:49
    • 23. Defining Variables

      7:54
    • 24. InputOutput Script

      14:26
    • 25. If then Scripts

      8:38
    • 26. Case statement

      7:04
    • 27. For loop Scripts

      7:43
    • 28. Do while Scripts

      5:40
    • 29. Exit Status

      8:48
    • 30. Welcome to Real Life Scripting

      1:04
    • 31. Accessing data from a file

      20:59
    • 32. Check Remote Servers Connectivity

      24:29
    • 33. Script Scheduling and Notification

      8:22
    • 34. Script to Delete Old Files

      10:52
    • 35. Backup Filesystem

      17:23
    • 36. For loops Scripts for File System 1

      24:52
    • 37. For loops Scripts for File System 2

      10:07
    • 38. Copy Files to Remote Hosts

      5:28
    • 39. User Directory Assignment

      9:14
    • 40. List of Users Logged in by Date

      15:30
    • 41. Script for Central Logging (rsyslog)

      23:56
    • 42. Script for User Account Management

      24:32
    • 43. Disable Inactive Users

      15:11
    • 44. Check Process Status and Killing it

      9:12
    • 45. Disk Space Status

      27:30
    • 46. Status on Total Number of Files

      8:38
    • 47. Create System Inventory

      33:00
    • 48. Getting Online Help

      13:04
    • 49. Congrats

      0:13
    • 50. Welcome to Bonus Section

      0:12
    • 51. Welcome to Bonus Section

      0:12
    • 52. Important Things to remember

      1:01
    • 53. Linux File Type

      1:27
    • 54. Wildcards

      10:01
    • 55. Soft and Hard Link

      12:16
    • 56. File Ownership Commands

      11:35
    • 57. TAB and Up Arrow

      6:27
    • 58. Combining and Splitting Files

      6:46
    • 59. Linux File Editor vi

      14:32
    • 60. Sed Command

      21:00
    • 61. System Utility Commands

      8:48
    • 62. System Log Monitoring

      11:08
    • 63. Terminal Commands

      6:18
    • 64. Aliases

      9:39
    • 65. NIC Bonding

      17:42
    • 66. File Transfer

      10:25
    • 67. RAID

      4:45
    • 68. Facts About IT

      4:32
    • 69. Difference Between Linux 5, 6 and 7

      14:45
    • 70. Securing Linux Machine OS Hardening

      24:26
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

640

Students

--

Projects

About This Class

This course is design for those who have some experience in Linux and want to learn or refine their Linux shell scripting skills.  Most of the scripts practiced in this training are based on real life examples.

For the hobbyists this is fun to do, for the aspiring Linux system admins these are essential skills and for the experienced Linux engineers these are skills to be consolidated

In this training we will cover the following:

  • Section 1 – (Lab Setup)

    ·         What is Virtual Box?

    ·         Downloading and installing Virtual Box

    ·         Creating first virtual machine

    ·         Linux installation

     

    Section: 2 – (Shell Scripting Basics)

    ·         What is Kernel?

    ·         What is a Shell?

    ·         Shell Scripting?

    ·         Type of Shells

    ·         Starting a Shell

    ·         How to Run a Shell Script

     

    Section: 3 – (Scripting Standards)

    ·         Naming Convention

    ·         Script File Permissions

    ·         Shell Script Format

    ·         Sequence of Script Execution

     

    Section: 4 – (Basic Shell Scripts)

    ·         Creating 1st script

    ·         Script to run basic tasks

    ·         Defining variable

    ·         Input/output script

    ·         Conditions/If else statement scripts

    ·         Case statement scripts

    ·         For loop scripts

    ·         Do-while scripts

    ·         Exist Status

    ·         Handouts

     

    Section: 5 – (Real Life Scripts)

    ·         Accessing data from files

    ·         Check remote servers connectivity

    ·         Script for scheduling and notification

    ·         Script to delete old files

    ·         Backup filesystem

    ·         For loops scripts for file system – 1

    ·         For loops scripts for file system – 2

    ·         Copy files to remote hosts

    ·         User directory assignment

    ·         List of users logged in by date

    ·         Central logging (rsyslog) script

    ·         Script for user account management

    ·         Disable inactive users

    ·         Check process status and killing it

    ·         Status on total number of files

    ·         Script to create system inventory

    ·         Getting online help

    ·         Homework

  • Bonus – (Extras)

    ·         This section has so many extra lessons on Linux

Meet Your Teacher

Teacher Profile Image

Imran Afzal

Systems Manager / Instructor

Teacher

 

 

Hello, I'm Imran Afzal and here is my education and experience:

 

 

About Me:

Imran Afzal

 

Education:

Bachelors in Computer Information Systems (Baruch College, City University of New York)

Master of Business Administration (New York Institute of Technolgy)

 

Experience:

- Over 20 Years of IT Infrastructure experience

- 7 years of training experience in Linux, VMWare, Windows and many other IT technologies

- 5 years of IT Infrastructure management experience

 

Certification:

- Linux Systems Management (New York University, NY)

- UNIX Operating Systems

- Linux System Administration and System Internals<... See full profile

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Syllabus Overview: Hi, everyone. Let's go. Our our celeb us. What exactly are we going to cover in this class? I have actually divided my class into five different sections. Section one, which is the lab set up in this section. We will cover what is award for machine. How does it work? Downloading and installing award jewel box creating first worship machine and doing the linens installation. Now, please. Remember, this section is for those who actually have never installed or who do want to install a lab linens machine in their laptop or their work station if you already have Ah, Lennox machine. And you wanted to start practicing your land exc scripting skills from this course. Then you could simply skip through this entire section and go right into Section two in section two will start off with shell scripting basics. And what those basics are starting with Colonel. How Colonel interact with shell. What is a shelter shell scripting How the shell scripting Come along. How can we take advantage off it? What are the different type of shells? Of course, there are tons of different shells. Eash Okay, Shal see, show bashful. What is our focus in this limp in this up in this class. And of course, our focus is bash scripting. But I will cover other shells as well. Starting a shell, how to run a shell script, then moving on to section three we have in section three. We will cover the scripting standards. What exactly the standards that you should follow when you are riding a shells. And those are how to name yourself shell scripts. In this way, you would have proper naming convention for your shells, script file permissions. So when you create a script, you would need a Pacific execute herbal permissions and what those permissions are, and how can we assign them, then shell scripting format. What goes inside of a script? What are the comments? What is, um where do you define the shell? What are the variables that sequence off shell script? Then we'll wing onto the section four, which is very going to start off his actual writing scrips, the basic shell scripts. And I'm not gonna overload you on this section with, like, huge script. So I'm gonna start. I'm gonna take baby steps with you as if you are starting fresh with me and Lennox Shell scripting. Then I'll show you how to create your first group script to run basic task in those task. Our system. Administrative tasks. Defining variables, input output, script, conditional scripts. If else statements groups will cover the case statements, groups look over. Four loose skirts will write it. I'll give you examples will create do wild scripts. How do they work? What are the exits Status? How can be used the exit status and shell scripting and make use off it. And then we have a bunch of handouts, as you could read on shell scripting that will help you write war script and understand scripting details. Six Scripting basics as well moving on to the Section five, which is our biggest section, and you should be ready for this section. By the time you come to this, you would know exactly how to start, how to get your hands dirty, and you are already on a driving seat. At this point, this is where we have. He will core their real life scripting examples, and some off them are accessing data from falls. Check remote server connective ity script for scheduling and notification script to delete all files backup file systems when you wanted to back up your system and you don't have a 1/3 party backup tool. How you could use a scripting language to do that? Four Loops Scripts for Fire System That is, for one of the section and I have not included just 14 loop This lesson. This Pacific lesson would have like four or five four loop scripts that I have covered in this one section. So in this one lesson, then four Loops group for file system to now. This is another lesson. I have split that entire lesson into two lessons. Why? Because I'm covering like 5 to 8 different scripts moving on copy files to remote host user directory assignment. You will see how we could check if if a directory exists and doesn't belong to a user. This is a security risk. How we could put a script around in real life examples. A game moving on to Section five. Section five is not finish it. List of user logged in by date Central Logging script. If you do not have Splunk, which is a Logan logging third party tool in your environment, it's OK. We'll create our own Splunk. Our own logging system locks script that will run like a Splunk collection logs script for user CAL management Disabled in active users. That's a scribble core check process status and killing it. Status and total number of files. Scripts to create system inventory, getting online help, homework. And there's gonna be so much, many other scripts that I cannot just add everything here in the syllabus that I will be keep adding it later on. So this is the This is what be actually going to cover in this entire course. So are you ready with me? Are you ready to go ahead and start? Let's go. 2. Welcome to Lab Setup: All right, guys, welcome to the lab set up in this section. We are going to actually set up our lab. Ah, where we will be practicing our scripting skills. We will be building. Ah, are Lennox machine and we will be creating shell scripts. So let's see, What exactly are we going to do in this lab? Set up? So this is Ah, quick, step by step, the instruction of what we're gonna be doing. Ah, following this lesson in this section, I will be covering about the virtual environment. This is for those who actually don't know what water environment is or what a virtual machine is. So I will be going over some of the fundamentals of virtual environment. How it works. Ah. Then what is, um, Oracle Virtual box? So, of course, inversion environment. There are so many. Ah, were actual products that out there, there's VM where the orca wardrobe box. There's Microsoft Works environment. So which one to pick So in our let lab said of you will be installing Oracle warship box, and that's where we will be setting up our next lab environment. So after that, we will be installing Oracle War troll box on it. Um, then it's Ah, it's a complete process. I have, actually, including every single thing in this set up. So where do you need to get the download file? How do you have to install it? How do you have to configure it? And then we will cover the first virtual machine. So once you have the oracle box running, then what do you need to do with it? You need to create a virtual machine. What is a word from machine? If you don't know, then I have covered that in this section. You don't have to worry about a thing. I will walk you through step by step and every all the way through on setting up your Lennox machine. And then once you have the Lennox machine up and ready, then we will do the Lennox installation. And, um, the Lennox insulation I will be covering is the centre west, which is exactly like Red Hat Lennox, which is used mostly in the linen environment in a corporate environment. So this section covers all about setting up your lab. Now, let me tell you this. If you already have a lab or if you already have. Ah, Lennox machine. Then you do not have to do this entire section. You could simply skip through it. You could start up your own Lennox machine that you have. It's either a bun, too. It's either sent OS or red hat. I would put forward that you go with center Wes and, um, and red hat because most of the scripting languages and the shell scripts that I will be using I was using in bash language. If you're lit Knicks opening system understands the bash programming language. That's fine. You could you could use that. Um, if you want to install Lennox from scratch on your physical machine, you could also go. You are. You're more than welcome to do that. But if you do not have any limits machine than this section is really gonna help you. And once again, if you do have a Lennox machine not to worry about it, just go straight to the next section. 3. What is VirtualBox: what is Oracle Worship Box? And, of course, why do we need to know about worship box? Well, for this course, you do need to install sent OS Linux operating system on your computer, and there are two ways you could insult. One. You could remove the existing operating system that you have on your computer. Or you could install virtual box on top off your existing Windows operating system or Mac, and then you could install sent Oso you This way you won't lose anything. So basically, a virtual box is a free and open source hyper wiser for X 86 computers currently being developed by Oracle Corporation. It insults on your existing Intel array, MD based computers, whether they are running Windows Macklin excess LHarris. It extends the capabilities off your existing computer so that it can run multiple operating systems on one hardware at the same time. Let's see how it works. So you have when the hardware layer and then on top off it, you install the operating system. Of course, it could be anyone. You have that as Windows or Mac, and then you install Oracle Virtual Box. It's just a A program, a software that you installed on your machine like any other software that you would install. Once you have installed Oracle warship box, then you could install the Lennox on it as a separate small version off operating system. You could have windows on it, or you could have Mac on it, said this one. This virtual box allows you to have multiple operating system on the same hardware. 4. Download and Install VirtualBox: in this lesson, we will cover the Oracle Horschel Box download, and it's It's insulation. First of all, you would have to go to Google and type Oracle Virtual Box download and then the first link you will see here go to download. If your operating system is Windows, you'll click on Windows Host. Once you click on, it will ask you to save the file. I can't save the file, but since it takes some time, I have already saved the file previously to save some time. This is the file execute herbal file that's been saved. Run, click. Next, Leave everything default setting. Create a start menu entry You. Could you believe that? Create a shortcut on your desktop? That's fine. Create a shortcut in a quick lounge bore. I don't like that and Register File Association. You believe that networking installing the Oracle Worship box and network feature will reset your network adapter connection temporarily. That's fine. Proceed 10 and stole. Do you want to allow the following program to run since installed software years? Would you like to install this device software from Oracle? Yes, if you notice quickly. This created a quick desktop shortcut on your desktop. It is trying to install another device software That's fine. Click Install. Just going to say, Always trust anything that's coming from Oracle Corporation and just click on install. So this week it's not gonna bother me again. And there you go, Oracle be impartial. Box installation is complete. Click start Oracle of Urschel box after the insulation. Yes, you could leave the check box cook finish and is Cancel this man Dairy go! That's the first welcome page off the wardrobe box. And that's where we have actually completed the installation off the warship box from a hair on you could build, create a new wardrobe machine. And once we create a new washing machine, we will install Lennox Santo s operating system on that washing machine. 5. Creating First Virtual Machine: creating virtual machine. In this lesson, we will create our first social machine. And on victory will be installing are sent OS clinics operating system. But worker machine is basically nothing but a shell. Ah, container, which holds the information off a machine CPU memory disc and all the resource is this fortune machine is gonna be sharing. The resource is wherever it is installed. So let's say if it is installed on my laptop, it will be sharing. The resource is from a laptop, the Oracle work show box. I'm gonna open it up. Okay, so this is the window for the Oracle Horschel box. I'm gonna click on new. The name I will pick is my first Lennox, the M. And if you notice, um, the virtual box is smart enough to OPEC, the operatives, his assistant type and version for you. You probably noticed that you are going to see the 64 bit. You are probably seeing 32 big. Now, if you are seeing a 32 bit, then either your computer is 32 bit architecture or the virtualization technology is not enabled. First, let's find out if my computer is 64 or not. So let's go to start menu computer. I'm gonna click right click and go to properties. Once the property comes up, you will see here it will tell you if it's Win seven PC and right here you're gonna see or is this system type? It's a 64 bit operating system. So that's one way. That's one of the reason that when I'm building my worship machine, it is coming up 64 bed operating system. The second reason you might not gonna see it 64 is if you don't have virtual technology enabled in your bias sitting. If that's the case, I have actually pasted an article and in my in this lesson and there is a link to it, I would recommend that you could go that link and try the settings that are recommended and see if it changes the 64 setting. I'm sure it will work. If not, you will always email me back. So I'm gonna leave thes setting sugar click next Now here is gonna ask me the size off the memory I want to assign to this virtual machine. Now, by default is picking up one gig off memory now, you should also keep in mind How much memory do you have actually in your laptop? So in my laptop, I have Let's look at my computer again, Right? Click properties, and you will see here. My computer has installed memory is four gig. So it is. It is wise that I keep the memory below that digit. That number. So I have four gig, so I'm gonna give one gig up that memory to dis virtual machine. I'm click next, create a new Horschel desk. Yes. It will create a brand new Horschel disk. Next, leave the default dynamically allocated. Lee the default post. Um then this is the size of the disc. By default, it picks a gig. I wanted to pick 10 gig just to be safe. So I'm gonna just click inside this box, remove and type 10 and click create. And there you go. This is my first worship machine that is created again. Think off it as a piece of hardware that's been created for me. I'm on the assembly line. I'm putting the CPU and putting the memory and putting the hardest. I'm putting everything in that machine and I built a machine. So once the machine is built, what is the next step? Next step is to install the operating system, and in our course, we will be working with Santo s up a ring system. So I'm gonna power this on, and I'm gonna install the operating system. But of course, before I go ahead and install the offering system, I do need the software ISO image. So in the next lecture, we will cover how we're going to download the IRS. So, software, and then how you could attach that software to this Lennox of'em, and then we will boot off off that software. 6. Linux CentOS Installation: Hello and welcome to sent OS installation. This is the fun part. Yes, this is where we going to get our hands dirty. We gonna go ahead and download the center Will s I s O image file from the from the Internet. Once we have it downloaded, then we will go through the installation. A complete installation off sent OS Lennox operating system. So you ready? So now I want you to go ahead and open up your browser. Any browser that you prefer, whether it's ie, Firefox or chrome. So let's go in. I have my browser open already. Um, I will go into Google now. The second step is you could use Google or any search engine that you like and I want you to type sent os download and hit Enter. Once you hit enter, you will get the first length I want you go and click on it. Or you could simply go and click on download. But first, let's go to this first link. So in the first slink or the first page, you will see download Santo s Now, Sometimes you will see three options in this page. One is a DVD. I s o second one is everything DVD I eso and 3rd 1 is minimal. I s o If you are seeing three or if you're seeing too right now, it doesn't matter because what we need is DVD. I s so this is the one that we need to click on. So go ahead and click on DVD. I So this will bring you to the links where the eyes are. Images are saved. So all those links are actually the links to the servers or they're often time referred to as mirrors. These mirrors, when you click on it, will take you to the file where the file location is. So go ahead and a pick Anyone off your choice over recommend that you pick the 1st 1 So go ahead and click on the 1st 1 Once you click on the 1st 1 it will ask you or prompt you to save the file. You have to save the file. Ah, to you to the locations so going. Click. Okay, if you do not know where the file is being saved, you see this little arrow here? If you are using the, uh, fire walks, he will see this little arrow here. Click on it and it will tell you that it is being downloaded. Right now. I do not want to download because I have already downloaded that file previously because I don't want to waste time, your time and my time to go through the company download. So let's minimize this page. Let's go to a desktop because all my, um, downloads go into my desktop now. You already have this center west. Okay, Now, I want you to go ahead and click on a double click on your Oracle War Troll box. The icon you have on your desktop. If you do not have that icon, your desktop, then you go to start menu and find that up and you will go ahead and start from here. When it opens up, you will see the my first Lennox for Lennox PM. The one recreated earlier. These two You're probably not going to see it because I was playing around with some windows. Were for machine anyway, it's just you could just ignore them. Um, click on the first, my first Linux VM and click on start. Now, this is powering up yours from machine. This is exactly the same way as if you powering on your physical machine, but pressing the button on it. So now it is asking, since this washing machine has no operating system, so by default is asking you to attach award actual disk to it. So it is asking where is the location off that were actual disc, which you want to install that operating system. So go ahead and click on this little icon which will browse us to our desktop where we have our eyes. So image safe. Click on this one, and you will see right here on our desktop folder. When you click on our desktop, you come down and you will see right here say, Santo s seven, which we have downloaded Ah, few minutes ago. So go ahead and click on open and click on start. Ah, by the way, this top thing right here is telling you have option to capture key ward option. Turn on. This will cause the upper virtual machine arm of the capture. You could just go ahead and cancel it. Now it's telling you at this green is selling you. This is a cent or seven installed center or seven. Test this media and installed center a seven, or do the troubleshooting right now by default. Test this media and install center. A seven is selected. You do not want to test this media. Usually this option is picked when you have a DVD install and the reason we do the test because sometimes the DVD have scratches on it. That's why we wanted to go through the test. So since this is I saw image. We don't do that. So go ahead and hit up arrow key on your keyboard and it will select or highlight the top one. It's State installed Cento a seven and now go ahead and hit. Enter It is actually bringing the eyes. So image copying the files that are needed to actually install the operating system so it will go through certain start up processes. It will start up the gui that will allow us to go through the installation off the lyrics Center s are bring system. We will give it a minute for the going to come up. See right here says starting installer one moment and installer. The Gui itself is called Anaconda. This is a name they have given Why? I don't know, But this is the name If you want to keep in mind Um you just remember that anaconda is the Gui tool or degree Viz erred. That will help you to install the Lennox offering system. Now you are under welcome to Cento a seven. Ah, welcome page. What language would you like to use during the installation? Ah, by default English and I'm in the United States. I'll pick English United States if you are in any other country. Ah, we recommend is you pick that country or if you want to pick a different language, you could pick that. However, I am not going to tell you how you could go through the installation with different language anyway, So I support for that. You stay on English and then you definitely you could pick a different country. Now go ahead and click on. Continue at the bottom. Right. Okay, so now it says, please complete items mark with this action. This icon before continue to the next step. Now the date and time is the 1st 1 we have already pre selected America's New York Time zone. If you wanted to change the time zone, depending on which times of your and go ahead and click on it and change the time zone keyboard by default. It selects English and U S um language support a gain. English United States installation Source. Local media, Which means that we are installing the operating system through the local Aiso image, so it's already been selected. Perfect. Next stop software selection. This is where it has by default the software selection as minimal install. If you leave that as is minimal installed, then it will install the lyrics operating system, but it will not have any gooey on it. Well, remember one thing most of the time. Incorporate Marmon. There are no gooey on Lennox, but since we are going through some practice, we will go through some GUI practices as well, because I do want you to know how Gui works in Lenox as well. So we'll go ahead and click on software selection, and that's where we will pick um, a couple of different additional software that are required in the middle installed. Ah, we have other options as well. If you want to use system administration tools are any other tools you could pick them. We could leave as default. Compute nodes, anything. Any debugging tools, directory clients, hardware monitoring tools, development tools. Most of these tools are used by developers. Since we are not going through the development training, we we will leave that. As is infrastructure server. Ah. What type off server are we going to run on this machine? I will tell you you could pick, um, anyone that you think you might need it later on. Um, you could pick the d n a server for now because we are going to core DNS, which is bind in this training so you could pick DNS if you do not pick Deanna Sarah this time, there is no issue. We could always insult the in a server or package later on, but anyway, just to show you how it works, I just selected one DNS name server. Anything else that you want to select here? You could. If you don't want to just follow my lead, then let's go to the next one says file and print server. You could leave everything as is a said basic Web server. You don't need it. Work authorization hosts and no several with Cool. Yes. This is where we have to come in. And if you notice as you are going down, all the other options that were available on the base environments are actually added here as well. So don't worry about it. They're repetitive. It's not that this option will have a different d n a server and with this based environment. So right now we are in the server with Gui Environment. I want you to go down and pick um que d e which is Katie easa. Plasma workspace are highly conferred with graphical user interface. I also want you to pick Java platform because if you are running certain application that requires Yaba, we could bring that up. Um, that see what we have? You have all the virtualization tool. Um, okay, I think we are good hair, but the Katie eat now The next one is genome desktop now Genome desktop are the ah, the desktop that also per wide some type of applications. Um, for the user, let's say if you want to use Firefox or if you want to use, um calculators or something on the gooey side, then you could select this. That stop as well. So go ahead and click on genome applications. Um, any other tools we need Internet application, email, chat, video conferencing software. We don't want that because most likely incorporate environment. You will not be using any of thes Katie plasma workstation workspaces development and creative workstation, and that's pretty much it. You don't really need any other applications or add ons for the selective environment. Now go ahead and click. Done. Now you will see this option right here. It will tell you checking software dependency. It means it is going toe our ISA image and asking that isa image. Hey, this user has selected thes these many packages. Do you have these packages for me to install on this harboring system is going to say, Hey, okay, no problem. Let me go ahead and check that. So it's checking the source, and it's checking the software dependency as well. So what is needed for those add ons that we need to install installation destination while it's running will go to the next one. It's his installation destination now. How do we want to protection our disk and solution destination right now? Says automatic partitioning selected If you want to change that? Meaning Right now, we have 10 gig. This is the discus size that we selected when we were creating the worship machine. This this size has shown up here is telling us we have 10 gig of disk space. How do you want to partition it? We're telling it automatically configure the partitioning if you know, or if your organization has a requirement to partition a disk into different slices or different partitioning than you will go ahead and click on. I will configure, Petitioning. Now, go ahead and click on. Done. Next one is K dump. Que dump is enabled If something goes wrong, K means Colonel, if there is something wrong with your system Ah, Colonel is going to write some messages, um, logs that is often referred in Lenox language as a dump that is enabled. So it's always a good practice to leave that enabled. So this way, if you are troubleshooting with your vendor, let's say if you have cento us red hat involved, they could go at and take a look at your logs. Next one we have is networking and host name. Okay, you We are on a network and host name configuration. At the bottom, you'll see Host name. Go ahead and highlight what we have right now and hit, delete and type in the host name off. The Lennox operating system will type the same one as we picked for R V M my first Lennox VM and click on Apply as soon as you click on apply. You'll see the current host name was changed to the host name that you have picked. Now the second thing is to configure the even it. Now, remember, by default if your machine or the washing machine, this is your washing machine. If it is running on a PC that has one gig, often network port, it will show up here as beat one gig, and right now it is showing its wired for me because I have selected or I are my machine where I'm running this worship machine is wired, so go ahead and click on configure and by default it will show up The tab as Ethan at E E and P zero s three is the name off our network adapter. So we'll click on General and we click automatically connect to this network when it is available that arrest of this setting is blacked out by default. You could leave as default I PV before setting is the setting for automatic DCP. If you want to assign an I P, then you would have to change it to manual. But we want the I P to be assigned automatically. So if you leave it as is I'm the last one is i pp six settings. We don't use that right now, so go ahead and click on safe. So once you click on save, you will see its tells you automatically connected. It is given an I. P Already. And now you could go ahead and click on Done. Okay. And so our network and host name has been configured. Now, the last part is security profile. No profile is selected. You believe that as as unless your organization has a specific procedure to put in place for security policies, then you could define it here. But for now, you could just leave as is, and go ahead and click on begin installation. Once you click on begin installation, you will see at the bottom. It will start creating your your partitions. That were selected that you ask the system to select it for you. Now it's going to starting package installation process. While this is going through the package installation, we have to, um, uses settings to define. First is root password. So go ahead and click on root. Password is not set. And here you would have to put in the root password. Pick anything that you you will remember if you notice I picked a week Password. You should pick a strong password if you are, Um, if you're working for a company or for you or an organization, But if you are just following my lab or you're doing this everything as a tutorial, that is fine. You could pick a week password. However, if you notice at the bottom it says the password you have provided it is weak. The password fails. The directory check. It is based on a direction dictionary word which you will have to press done twice to confirm. So okay, I understand it is a weak password. In order for me to keep that password, I have to press it done twice. One to now it has taken that weak passwords, user creation Let's go ahead and create our first user. Full name. Let's put in our first name by default. Lennox takes the first name as the first letter. First initial last name is complete. Last name. So for me, the user name will be I of soul. Keep your user name shorter than 32 characters and you do not use spaces. That is fine. We are not using any spaces were wholly using six letters. Make this user administrator. You could lead that out. Requires a password to use this account. Yes, the pickup password. Again. It is weak. I understand. And I would have to do the same thing Done twice. Okay, it is done. Now if you come down and you notice right here it The operating system is installing or this Viz erred is installing packages for this offering system. Total number of packages that are required to be installed are 1397. You might have a little more or a little less, but that's okay. It depends and it changes over time. What other packages are installed? Water. The dependencies aren't still so again, If your packages do not match with my packages do not panic. You are. Okay, so now you'll see it is going through the packages installation. At this point, it is. It has installed almost 400 packages and they're still about ah 6 to 800 packages that needs to be installed. And this process will take. I would say somewhere between 10 minutes to 30 minutes, I am going to fast forward this entire process to save time. Now the packages installation has been completed. Now it is going to some post insulation set up. All right. Finally, our installation has been completed successfully. Now Santo s is now successfully installed and ready for you to use. Go head and reboot to starve using it. Click on Reboot West. Since the system comes back online, it will give you the initial set up page. The first page is about licensing. You have to accept the license. Click Accept license every hman click on done network and host name if you notice. We have already selected this network and host name configuration during our installation so that you don't need to do it again. Click done. And right here says finished configuration. Go ahead and click on finish configuration. All right. Finally, our entire Lennox installation has completed. Now we have to log in the first time, Click on your name or you could also log in as root. If if you remember, you have picked the root password, you would have to click on, not listed and type and using him crude and password. But for now, we'll go in as ourselves and we will put in a password, click on Sign in or had enter. All right, this is the desktop. This is how it looks like in Cento as it is very similar to Red Hat Cento s. You have these icons right here. You can resize them if you want to. You could delete any I conjugal create icon. Um and you could explore other things on the application and spaces. So also, one more thing when it starts up, it also gave you this welcome page. So you just leave as English. Go ahead and click on next typing. If you want to change anything you believe a default location services, I usually keep it off. If you want to leave it on, it's really up to you. Click next connect to online accounts. You don't have to do that clicked, skip, and then start using sent Os Lennox. So once again, congratulations. So now you know how to do the complete Lynn accent OAS installation? If you think that you missed something that I would recommend you to go ahead and delete this entire Lennox, we m and go ahead and create a new washing machine. And do the Lennox insulation again from scratch. The more you do, the more practice you'll do, the more you will learn. All right. Good luck. 7. Welcome to Shell Scripting Basics: welcome to the new section off shell scripting basics. That's where we actually will learn. What really a shell scripting is what are its basics? You know, starting from ABC or 123 So that's where we're going to start. So let's see, what exactly are we going to co were in this entire section? So we will start with Colonel. What, exactly? Colonel is. And how does it interacts with the shell? And is there a colonel in operating system? And how does it interact with your hardware? And how does it interact? Was your shell and your operating system? What exactly Shell there's. Of course, this is the main thing. We wanted to know how the shell scripting works. There are so many types of shells, there are corn shell there, bash. There are, um, seashell and so many that I will cover in this lesson. Then we will have starting to show how you gonna start a shell if you are in logged into into your links machine and by default, you have a bash shell and you want to say sure, definite show. How do you do that, then, Wilko? Or how you gonna run a shell script. So you have created a script. Now how do you run it? So this is a few things Very basic ones that you should really know. And this is like a fundamental things that you should understand and put it somewhere you know, deep in your head that outside of the thes are like a actual guidelines that you have to follow in order to run. Ah, perfect shell script. So you would know when if there is an error message or if there's a problem when you're running a shell script, why did it happen? This section will explain you if you really go through it. 8. What is Kernel: the next Colonel. Do you know there is a kernel in every Lennox distribution or UNIX distribution? What, exactly a colonel is? It actually interfaces between your hardware and your software. So let's look at this diagram. Here, you will see you have at the bottom is the hardware and what others? Hardware hardware is like CPU memory, hard disk and any, um, outside hardware peripheral devices. Then you have Colonel. A kernel is a program that is stored inside off your operating system. It's like a program, a command that keeps on running. And what it does is it takes the commands from shell and shell. What is a shell shell? Is anything like a gooey Davey having windows or a gui in Lennox? Or if you don't have going Lennox, we have terminal that runs bash shell or sea shell, which will cover later on. So when we are in that bash of seashell terminal environment, the execute commands. The commands are being forwarded to a colonel, and it's kernels responsibility to talk to the hardware that's inside off your computer, and then you on top of that, you have a browser, send mail, all the application that we're only calculator, calendar office or any limits related applications. And, of course, on top of that is are the users and that is you. So Shell and Colonel together, that's offer built together in one package, and that is called operating system. And that operating system is any operating system like Lennox, UNIX, Mac or Windows. Every operating system has that little program that actually talks to your hardware and anything that is a shell, which is written in C programming languages. Well, that shell or that those applications are actually the software. So this is what the real colonel means, and we really need a colonel in any operating system to talkto our hardware. 9. What is Shell: shelter. What is a show in this lesson will cover about Shell Hollow shell works and how you grown command within the shelf or how the environment it's set up in a show. So what exactly is a show show is like a container like you know, you have, like a top aware in your home or any kind of containers that holds your environmental information inside off it, it's interfaces between users and colonels or offering systems. So you have built an operating system, and then it is provided a platform you to execute commands again. Ghulam Windows is one of the platform and and now have been is offering system. When you start up a gooey, you execute commands by running. But double clicking on a program so that go into face is your shell. In Lenox. When you don't have a gooey, you are given a terminal show or cli command that is your show. To find your show, you could Aronica man like eco dollars, dollar and zero that would tell you what shell you are in. And you could also get a listing off all your shells in your Lennox distribution by running the command cat at sea shells. Your shell is also inside off, etc. Password that is defined inside off the file you and windows. Gooey is a shell in Lenox, Katie Eglise a shell and let S h which is shelled Bash sector. All these are the show that is provided to a user again. We're looking at this diagram again, and we are second from the top. You'll see the application that talks to the shell and then shell talks to Colonel and Colonel is the one that is telling hardware what to do. Let's look, look at our Lennox machine and we'll see how we could find our show. Open up a terminal real quick and when you do cat. So when you do echo dollar zero, it tells you you are in bash So you could look at the available shell that is installed in your distribution by doing cat at sea shells and tell you all the shows that are available . And when you look at Etc Password, cat, that seat password and you'll see in my user name, which is right here. It tells the shell is all the way at the end that I have a defined show, which has been bashed. I could change the show if I want to tow a different show, but I try to keep it consistent with other users so that what the shell does, and we'll cover the later in the later lessons how we could talk to Shell to create scripts and other things to automate our tasks. 10. What is Shell Scripting: So now let's talk about what is a shell script. So put all your instruction in a show or in a container and just running. So if I have to explain it through a diagram, let's put it this way. This is a shell, right? Like actually a shell. So you actually putting all those things All those instructions like do this, do that, or else do that it sector everything. You putting that together in a shell and then telling Shell, run this set of instructions and, of course, run them in a sequence by default, the shell runs old instruction in sequence. Now, if you notice you goto windows and you want to copy a file from one folder to another, you right click to it or control, see to it and then you go to another window and then you paste it. Now how does it work? How does Windows knows that I have been given instructions to copy it and paste it, because when you right click and give you the option to copy and then you go to under the window gives you the instruction to paste that is the function off a shell. The shell is copy instructions to copy a shell is instruction to paste. So just like that, any out the commands or any off those functions that you run and windows, they are all created within a shell within a commands. You don't see those commands. And in fact, if you wanted to really run and Windows, you, you could just go toe open up the DOS prompt and you could actually run those commands a copy command to copy file from another. But of course, Windows. Microsoft had made your life a lot easier to run all those commands through graphical interface, which is Click click, click now in Lenox. You don't have that luxury, and that's why I also Lennox is difference it because it's not gui based, kind of, um, operating system. It's a command line, so you could run your function a lot faster so you don't have to deal with gooey and go using up your CPU and memory. So what do you do? You run, copy command or you run, Move command or all those commands that you run. Those are what are those? Those are actual the scripts. Those are shell script and who have written those the developers, those people who have done development, those people will do C plus plus or C development. They create those scripts so you could use those scripts leverage on those scripts in Creature own Shell script. So that's how the shell scripting works. 11. Type of Shells: No, let's talk about the different type off the Lennox shells that are available to us in our Lennox environment. When we have a Lennox machine running, what are the different shells of he could take advantage off? The 1st 1 is genome. If you don't know what genome is, actually, genome is like a graphical environment that is in Lenox. Now. You must be thinking home isn't Lennox command line interface. It is most of the time, but there are people who actually installed Lennox with the gooey and the gooey while you were installing the gooey. Or while you're going through the installation, you have the option to install Gui as well. And the two options that you have for Gui is genome, and the 2nd 1 is K D E. Both of these are the desktop gui environment, and they are the shells. So you log into those environment you are in the show and then you run command. How you execute commands you to execute your keyboard and through your mouse you click click, click, drag drop here and there. That's how the interact would the operating system through that show. Now, of course, let's go back to our main topic, which is the command line chills. Now the command line shows the main one is shell is just s h shell. Of course, this is we are now talking about when we do not have a gooey We are in a command line. And now we need to use a show. When you use the logs in, um, a user is given a shell a platform to work. That platform is assigned to the user when when the user account is created. So as I mentioned before, if you go to Etsy past where you will see your shell So if you are let's suppose are given bash shell by default and you want to switch to S H. You could do that by going to a different shell. How do you How can you do that? We'll cover that later. So show this just s H is a born show Call. Sh R s H is one of the original in eggshells. It is developed by UNIX computers by Stephan Born. His name was actually born. That's why they picked the name born chill from he worked for AT and T Bell Labs in 1977 Those are one of the oldest days when actually let exports or UNIX was being developed. Its long history of use of means. Many software developers are familiar with it. It offers features such as input and output redirection shell, scripting with string integer variables and condition testing and looping. And so many of the things which, of course, don't worry about it. All those the heavy words will cover them later in the lessons. Then we have Bash Bash What is it now? The popularity off shell which was S h was so so much that you know it made it. It actually motivated programmers who actually developed the results show that was compatible with it but with the several and has men. They added so many things to it. Lennox system still offer shell scripts They came away with bash so they still have show. But now they came up bash Know what bash means? It means born again shell. So if the shelves still exists somewhere, don't think that shell S H is gone. Now the newer shell is available, which is called Born again shell. And in our entire course, we will be using Born Again shell. Why? Because it has a lot of enhanced features, and it is very user friendly. So maney, um, features of variables that we could use in that show. Then what out what their other shells there is. Seashell and T C. Shell developers have written large part of slings operating systems in C and C plus plus language is right, you know that using cease in Texas, a model Bill Joy, who was at Berkeley University, developed a seashell in, ah, believe 1977 or 78 then the Ken Ken Greer. I think that was his last name. Working at Mellon University took seashell concept as a step forward, and when it took several, what did he do? He came up to the New York show, which was T. C Shell and based on your system directory structure and follows. T Shell does not run bash scripts. Eso um, if you are in a t shell and you want to run bash, it's not gonna run it anyway. Most of the people don't use seashell and T shells unless you really are proficient in C and C plus plus programming language. So my advice to you, you could stay away from it. If you are a beginner not to worry about these, then the last one we have is corn shell or Keisha David Corn. OK, see, that's the name. So that's why the people came out with the shelves because they associate ID. The name, whether so the person who came up with a corn shell His name was David Corn. He developed a corn shell on dumb. It was about the time like T. C. C shell was introduced. So corn shell is compatible with shell and bash l as well. Now core Shal improves on boring shelled by adding floating point automatic job control and so many of the things I don't want to confuse you right now. Um, injure UNIX environment. Um, most of time. Corn shell is used in Solaris where, as in Lenox environment most of the time, a bash Ellis used, as I mentioned again, If you need to know the list of shells that you have installed in your system, all you have to do is go into you, log into your linens machine and type cat s sea shells, and you will see all the list of shells. So this is what I wanted to cover, and I want you to be aware these are the different type of shells. If you are creating a shell script and you need to get help on creating a shelves, let's say, if you google it, maybe you will find some off the information or some of the US ah, scripting syntax in bash and some off them in corn shell. So you have to be very careful. They're probably not gonna work on one another. That's why you need to know the difference off different shells. 12. Starting a Shell: Okay, Now we know a lot. About what other different type of shells. How do we start a shell? How do we get into different shells? Well, it's simple at is simply type shelling. Meaning, if you are inborn shell and you want to get into, um, just shell or seashell Just type S h or just type C show. So, um, without explaining you, Maurin detail Ah, log in straight to ah, my Lennox machine and I'll show you how you could switch from one shell to another. Okay, so I have this limits machine and you notice that I have the school he running in. Medics inside the gui I have this terminal so all the commands that I run from the terminal is actually a shell. And that shell is how do you find a show? You do echo dollar zero and it tells you my shell is bash. Now, if I don't want to use this command line and you see in the back I have this directory called home and I have this trashcan. So if I wanted to view the contents off home, what I do a double click. So this environment right here is. You see this environment is G. Norman Mark, remember, I told you genome is also a type of shell. So this is another shell right here, and this is command line Inside is into the show. So if I wanted to open this folder, I am telling genome, which is the desktop gooey to open up their folders a double click, and it will open up the contents off that directory. And these are all the directories I have these. This is a file I have off off all the directory. If I want to go into another director and in the file, or if I wanted to open up this file, I'll double click and D Genome Shell is interacting with Colonel an operating system and telling it to open it up. Now, what if I do not have the school environment? Right, So and not everyone is a windows. Um, not everyone. Um, I wanted to get into windows. They want to get in the command line. So what did they do with a? So if if you want to ah, view the content off my home directory, I'm sure you know the leg up output. I'm sure you know the output. Um, off pwd, which means home. I have salsa. Now, if I wanted to save you the content of my directory, I do ls minus l And you see, here is a list off all the directories did I have in my home directory. So I did the same thing as I was doing here by double clicking it. But right now, I used a command Ellis. So when I use the command, Alex, I actually am telling my bash shell to do this. L s command for me. Well, let's do clear. And it will clear up my terminal. Now. If you wanted to see of what other shell that you could, um, change too. You could just simply type S h and you hit S h. You see yourself shell prompt changes. You could also verified by running echo dollar zero and you'll see it is shell. Now, if you want to exit out of the shell to go back to your bash, you type exit. And if you want to go to, let's say seashells, so just type seashell and you are in seashell to confirm your in C Shall you do echo dollars, zero seashells. You want to get out? What do you get? How do you do? You do accent. So had That's how you get out. Now, what other shell that we learned? Let's say if you want to start a corn shell s que S h hit, Enter. Um, this is bash. Corn shall command not found. This is similar commanders you could use Regency shall know what I want to use corn show why I cannot get into corn show. Maybe because I do not have corn shell installed in my computer. And how do we verify it? Simply do cat shells. Okay, tell me, do you see corn shell in there? No, right. That's why I was not able to start that corn shell. Ah, shell, actually. So anyway, so that's how you could switch around chills. Start a new show again. This is if you want to get into a different shell environment. Now, how does it relate to shell scripting the shot scripting that you want to learn, right? That that's what you're probably thinking? Well, if you are creating a shell script, let's it in corn shell. And as you see right here I don't have corn shell. That script is not gonna run. So you need to know your environment beforehand before you spend tons of number of hours and then realize, Oh, boy, I don't You would have a corn shell and, you know, even how to install or down on the corner anyway. Eso That's about changing the shells. One of the basic things that we should know is how to run a shell script. So when you created there are different ways you could run it, you can run it through absolute path, or there's another one that's called relative Path. So absolute path is if, let's suppose, if you are standing right at the first step off a steer's and you have to pick up something on the very last year in the top, you have to actually either shoot from the first year all the way to the last year on top and grab that thing that you're trying to grab or there's another one. Another way is relative path. The relative pat is that you actually walk up to the steer and then grab that thing that you wanted to grab the same way. Um, absolute path and relative pat works. If you do not know what exactly, absolute path and relative pats ar, I would recommend you that you should, you know, try to look it up online and see what they are and how they work. And, um, you'll find tons of article there and make sure your type, Absolute Path and Lennox or absolute path and relative path in Lenox as well. So the way it works is I have my limits machine up. Let me log into my Lennox machine, so I have my script right here. It's called X Y Z Dash Screwed if you notice I am in my slash home slash I of Salt and Slash script directory. I created a directory called Scripts in My Home Directory on Guy. Create all my scripts in that directory. So if I am already in that directory, I could run the script or if I am not in my directory, let's say if I just do CD and which directory I'm in, I'm in slash route. So the script that I want to run it's just a test group that I created earlier. That's a few tight death script Name. X y Z Dash script and then you hit Enter, you'll see it says Bash the script. Name Command Not found. Why? Because the Lenox operating system is trying to find that script and slash root directory. And I do not have that script in slash root directory. So I would have to specify the absolute path to run the script. And the absolute path would be just the same way as if you are standing at the bottom of the stairs and then you have to fetch something from the top of the stairs. Then you actually through some kind of means or like a stick or something, and you could grab it. So the same way you will specify the entire path, which is slash home my user directory scripts and now the name of the script. Now when I run the script, I'll hit. Enter and you will see is just the script that is actually echo out or print Hello, world on the screen. How does this group created? I will cover that in the later lectures, but just to focus. This is how you need to run a script using absolute path. Now what if you are in a relative path, which is that you are already in home I of salt and Scripts Directory. See you CD into that directory. You do PWD and you'll see the path is the complete paths. Now. Now the script name is again when you do Alice, my cell tr I have the script X y Z script. Now when you run this group now script and hit, enter it still cannot find it. Why? Because when you are inside off a directory, you will always have to specify that you want to run the script but than this same directory. And that is the relative path. And to do that, you have to specify dot, slash and then the name off the script you could hit Tab. It will auto complete. So now you hit enter and you'll see it ran. So keep that in mind. There are two ways you could run the script one through absolute path and want to the relative path. If you are, let's say in slash home directory, and now you want to run the script. You could still specify the entire past lying home starting my user directory, or you could just simply start from the director you are in. So you are an I absolve from from this home onward, I have saw scripts and the script name hit, enter. And you see it works here too, because you you have to let the opening system know where your script exactly is located. So that's the basic about scripting how you run it. So please remember these two main points about running. 13. How to Run a Shell Script: one of the basic things that we should know is how to run a shell script. So when you created there are different ways you could run it, you can run it through absolute path, or there's another one that's called relative Path. So absolute path is if, let's suppose, if you are standing right at the first step off a steer's and you have to pick up something on the very last year in the top, you have to actually either shoot from the first year all the way to the last year on top and grab that thing that you're trying to grab or there's another one. Another way is relative path. The relative pat is that you actually walk up to the steer and then grab that thing that you wanted to grab the same way. Um, absolute path and relative pat works. If you do not know what exactly absolute path and relative pats ar, I would recommend you that you should, um, you know, try to look it up online and see what they are and how they work. And, um, you'll find tons of article there and make sure your type, absolute path and Lennox or absolute path and relative path in Lenox as well. So the way it works is I have my limits machine up. Let me log into my Lennox machine, so I have my script right here. It's called X Y Z Dash Script. If you notice I am in my slash home slash I of Salt and Slash script directory. I created a directory called Scripts in My Home Directory on Guy. Create all my scripts in that directory. So if I am already in that directory, I could run the script. Or if I am not in my directory, let's say if I just do CD and which directory I'm in, I'm in slash route. So the script that I want to run it's just a test group that I created earlier. That's a few tight, that script name X y Z Dash script, and when you hit enter, you'll see it says, Bash the script. Name Command not found. Why? Because the Lenox operating system is trying to find that script and slash root directory, and I do not have that script in slash root directory, so I would have to specify the absolute path to run the script and the absolute path would be just the same way as if you are standing at the bottom of the stairs and then you have to fetch something from the top of the stairs. Then you actually through some kind of means or like a stick or something, and you could grab it. So the same way you could specify the entire path, which is slash home my user directory scripts and now the name of the script. Now when I run the script, I'll hit. Enter and you will see is just the script that is actually echo out or print. Hello, World on screen. How does this created? I will cover that in the later lectures, but just to focus. This is how you need to run a script using absolute path. Now what if you are in a relative path, which is that you are already in home? I of Salt and Scripts directory See you CD into that directory, you do pwd and you'll see Pat is the complete paths Now, Now the script name is again when you do Alice, my cell tr I have the script X y Z script. Now, when you run this group now script and hit Enter it still cannot find it. Why? Because when you are inside off a directory, you will always have to specify that you want to run the script but than this same directory. And that is the relative path. And to do that, you have to specify dot, slash and then the name off the scrip you could hit tab the auto complete. So now you hit enter and you'll see it ran. So keep that in mind. There are two ways you can run the script one through absolute path and want to the relative path. If you are, let's say in slash home directory and now you want to run the script. You could still specify the entire past lying home starting my user directory. Or you could just simply start from the director you are in. So you are in Iove solve. From from this home onward, I have saw scripts and the script name hit enter and you see it works here, too, because you you have to let the opening system know where your script exactly is located. So that's the basic about scripting how you run it. So please remember these two main points about running the script 14. Welcome to Scripting Standards: welcome to Section four off scripting standards. What are the basic standards that you need to remember? Some off them that we will cover in this entire section is how you need to name your script . What are the naming convention that you should use? Okay. Hey, I know how. What? Naming convention to use? I don't have to worry about it. I would remember everything that I would know. Okay, if you do know that, be my guest. Skip ahead to this lesson. Double cover, But trust me down the road if you are. If you have created a script a year from the time you created script, you will forget it if you do not have in a proper naming convention. And if you do not have in a proper directory structure, so we'll cover about the naming. Convention will cover out how the script permission works. So when you create a file by default, it does not assigned executed permission. If you want to read a file, it has to have a re permission. If you want to execute it, it has to have execute permission. We'll cover that in that. In that, um, lesson. Then shell script format. How you should write a shell script. What are the formats? Um, standards that you should follow, followed by the sequence of the script. Execution. When you want to execute certain things inside off your script, you want to execute ABC. You need to know how they are executed. And the last one is the variables and how to create them. Variables is just like aliases will cover that in this in this section as well. So these are the basic things again. If you know all that, be my guest. You could fast forward. But I would highly recommend you to please go over and And so this way you will have the right standard in your in your memory and you will know exactly when you're starting it from the get go. You know how to start from the right path. 15. Scripts Naming Convention: Okay. Script naming convention. What are the names that we should use when he created first? First of all, I will tell you that every time you need to create scripts in your links environment, always created directory, call it scripts or my scripts. Or if it's a project based scripts type of like http directory or, um, payroll directory, where you're going to create your scripts. Directive structure is very important, so you don't you don't create scripts all over the place. So follow the standard creep creature directory, which ever folder Just you picked that you want to create your directory in. That is fine, then script name. The script name should identify the function if you are going to get into a job or if your job functionality is revolves around creating a lot of scripts, doing a lot of automation than it's best that you name it, that matches its purpose if you wanna. If your script is going to check the date, um, checked today's date and you are naming it X Y Z. Then again, a few months from the day you create, you're gonna forget what X Y Z is for, so it is good that you name it like date or something. My date script or something like that. And the script should end with a shell if you are using bash so that I would say right the name off the name of the script Followed by dot B a s h. Now, this rule this rule should only be used, which I usually follow This rule when I am creating multiple shell scripts. Meaning if you were creating shell script in corn shell, seashell, pearl or bash, then you you need to have the extension at the end images dot s h dot corn shell. So these are the few three basic standards that you should have. Let me log into my linens machine and I will show you exactly what I wanted to cover here. So if you going to your the next machine and you log into your home directory, let's say my home directory is slash home slash i absolve in my home Director. You notice I have Ah, Derek, you call script. So this is what I mean. So every time you create a script, you need to create a directory first. So this way you go into your script directory. So they say, You know, you don't have to scroll through on and find out where your scripts are. So in my home directory, you'll see I have a very few files in directory, so it's very easy for me to find out because it's a test environment. But maybe you're working in an environment where you create thousands of directories. So that's why it's important to create a doctor. Call a script once you create this cryptic tree, then you could just go in and you'll see right here in my home directory, I have a script called X y Z Dash script. No, as I mentioned X Y Z desk grip, it's not a really good name. You cannot tell what exactly it does. So if I run the script, you'll see it actually spits out Hello, World on the screen. So that's exactly what it does. If I wanted to associated that script with the named and I should do is X Y Z scrip. Move It move is a command to change a name off a file. I'm sure you know that, and I will say, um, hello world or W or O complete name. That's fine. And I will run that command and you'll see now my script name has changed to hello world. Now, if I am using multiple shells, then I should label it as move Hello world dot So hello, world Dodd B A s h This way. If I'm creating multiple script and corn shell or C shell, then I would know that this script was created in Bash. So this is basically very quick lesson I want to cover. Remember that this is the standard that you follow. Also, if you are doing that type of work in your environment and that you decided to leave your job and move on to another career and then the person who's gonna come and replace you that person I'm telling you is gonna be so happy or even your manager is gonna be so happy that you are so organized that all the script that you created while you stayed with the company are all organized and where to find them 16. Script File Permissions: script file permissions. Now, this is not just theoretical or concept or standard that I'm trying to explain it to you. This is actually mandatory. You need to have the right permission to execute a script and to and to have a proper permissions on the script file itself. So all scripts to be executed should have a proper execute. Herbal file permissions. And those are, for example, if you see here it's read, write and X is for execute herbal meaning the route. The person who created this group can execute it. Then read Dash X meaning the group who belongs to the user or the user belongs to a group, has a right to read and execute this crew and the last one are the other people who do not belong to your group or there are not you. They could also execute that script and read it. But of course they cannot write it because you don't see that w and W in the middle of group and others. So every time you create a script, you need to assigned the execute herbal permission. Okay, so now you're probably thinking, haven I create a script? Why can't it. Get a signed by default. Executed permission Question. But the problem is that whenever you create a script in Lennox or whenever you create ah, file, I should say in Lenox, by default, it does not assign execute herbal permissions because it doesn't want you to make a mistake and executed something by mistake and corrupt your file system. That's why it doesn't give the executable permissions. You have to sign them yourself. Okay, now, I created a script. Now, how do you change the permissions? Simply the command to change the permission is CH model A plus X and the name of the script . A stands for all. Everybody should have executed Bill permission off the script I use. I prefer, um, letters as a our, um, g or Oh, for user group and others. There are other people, or you probably are familiar with the digits as well. Like 65567 Something like that. Which I I I'm not too much familiar. I try to follow something that I am very familiar with, and I would like to teach you something that I know. Anyway, if you are comfortable with your own way of saying Permission, be my guest. You feel free to use that Now let's some see. If I log into my machine and I create a script, then how can we change permission? So let's see. Where is my Lennox machine? My Lennox machine is right here, and I am in my slash home slash I have solved slash script directory. I wanted to create a script and there are few ways you could create a file first. You always create a file. You could touch it. You could be I it and you could echo it and output to a file The different boys, whichever way you want to start creating a scrip. So first thing I will use a very basic is touch And the name of the script. Let's say script name is a party script had entered. Now when I do, at S minus lt are you'll notice the script that I had before. Hello. World has the execute herbal permission, right? This is the third but you see your way here. The new script that I created which is Apache script, does not have the execute herbal permission. So in order for you to run that script you need to assign execute herbal permission to assign the permission. You have to run the command change marred as I said, I'll use for all. Everybody should have executed Herbal plus X for execute Herbal The name off the scrip hit . Enter now duelist minor sell to your You will see the name off the script and it's correct . Permission. This is how you assigned permission? Very easy to do that. If you're already in Lenox, you've been using Lennox. You probably like ho. I know that. Perfect. If you know that, let's move on. 17. Shell Script Format: script format. Having a proper format inside of a script is very important. Why is that? Because I'm going to say I'm gonna bring back the same analogy. You create a script. It's a very long script, and a few months passed by, and now you need to modify the script or troubleshoot something in the script you have. Sorry, you have written down the script, but it's all over the place. The variables is up. Your comments are nowhere to be found. The description is nowhere. The commander left and right. There is no Indention, nothing. So there should be a proper format that should be followed so that someone can come in and take a look at your script, insist. Wow, that's a great job whoever did that so easy to read and so easy to understand. And what are those format? One is first and foremost is defined shell. This is something that you have to define. You could say it is a part of format are mandatory. You have to do that. You have to define a shell. Then you create a first script. You have to let your operating system no run that script as Bash script. If you're doing a corn shell, you'll have to specify pound hache slash bin slash corn shell. Anyway, when we write, our first group will cover that as well, then comments. Right after defining the shell, you have to put the comments, and those comments always starts with pound sign. And the reason I am telling you that you should include comments is because common should tell what your script does When your script was written who it was written by, Was it there any modification, anything that you wanted to include that a user o R. Someone else reading your script can understand what this script is about? Please add that to your comments, then defined variables, variables what Those variables are real. Cover that not to worry body, but just to let you know quickly. The variables is just like an alias. If you have a long command or if you have ah, a bunch of emails. What people do is they give it, um, a letter equals the whole big command that becomes their variable, so define your variable at the top after comments. Then you run the commands, whatever the commands that you want your script to execute. You need to specify those commands or if you do not have command or if you have any statement scripts. That's where you put your statement scripts. Those statements groups are if then, while for loop or so on. Now, when you have statements defined, you should start. If the line where you gonna put an if hit tab? Because this way it will show that you're f statement is starting. From this point on, there is nothing that that script will translate your tab into something else. You could use spaces. You could use tabs, anything that you want. But try to make your script formatted in a way that if someone or even you read it after year to year, you'll say, Ah, this is what I did it so easy to read. So let me log into my linens machine again, and I'll should tell you exactly how you should format your scrip. Okay, this is my Lennox machine. I'm already in my directory. Perfect. I created a script earlier, or a file earlier. Call Apache. I'm gonna take that same script, and I will formatted the way I have just disgusted so to do that. I have to now do a V I on that screen. And I am sure you guys know how to use a V. I some some of you are familiar with them, which is probably in a Hass worsen O V I. I like to use a V I It's kind of old school, but, um, the good things that it's available and pretty much all the units or her linens flavour So I could never learn something new and not utilize it on older version. Because I use V I in many system like Solara, say I X systems. And sometimes vim is not available. So v I is something that you will find anywhere, whichever the system you logging. Anyway, I'm gonna use V I to at it this file which will eventually become a script. So you hit, Enter now the first thing. As I said, you have to define a variable. It had been bash. If you look at the back, you'll see the first thing is defining your shell. I want to run this script as bash script. Perfect. Now the next thing I said to add a comment, Okay, I always add a comment. As usually add a comment is like purpose testing script format date. Put any date, Let's say August 22,020. Um, modification. If you have done any modification to the script, put down the date off the modification. So zero to 08 So last modification. Of course. Since you're creating the first time, I'll put 20 again. Okay, then anything that you wanted to add, Please Go ahead. Do so. So if I just put in block love whatever, it's just a common. It has no effect on your script. OK, Perfect. I understand Imron. But how come the first line that you have is slash bin slash bash has a common in front off . It isn't, that isn't it will be considered as a comment as well. Awesome question. Trust me, I had the same question. But let me tell you, this is just how it is. Sometimes you know, it is how it is. So the Lenox will understand this as actually a shell script, and it always starts with pound and hash. Why? I honestly don't know. If you really want to know why you could ask someone else who really know inside out when they came up with, ah, writing scripts. Or you could I'm sure, um, go online and find out why you have to define with hash. But anyway, put that in the back of the head. You have to remember there's no matter what. Okay, so moving on, then you define next thing is variable. Variable is something like I want Every time I want to echo something, I just want to say a and then echo. So let's say in my case, I wanted to have, um single coat Imron epistle. And you know what? All the same, my name is Imron. This is how you define your variable And then you could just do echoed dollar a Then it is going when you say echoed dollar A By the way, this is this a scripting language? I already started teaching you, but that's okay. Ah, you need to understand the format so variable I have defined here that every time this command will run, it is going to call upon this variable. Why didn't I put that whole thing here? I can't, of course. But what if you are working an environment that requires a huge line and does huge things. Then you it's better that you put those variables in there. Then, of course, then you put command. Let's say you want to run a date. You want to run a command G of minus age or so on, then The last one I included as statements. If you are including statements in your script, please do not start from if, let's say, um, dollar a equal. Um, that's a file or whatever. Do not start like that. Always put tab like this. So if something is equal to that file, enter and then tab again then echo this else echo dad and then fee to close the statement. You see how it is that if Kantar if statement came to be on the right hand side So you know that this is the statements that I want to run and they are and then did to the right side . What are those statements? Kits? I never seen that. Don't worry about it. I'm gonna cover that in my next lessons. The purpose of this lesson is just that you know that. Why would I follow this format on the following lessons? That's why I want undercovered that right now, so you wouldn't know. This is the best way to put your scripts together, and it will be so easier to remember when you come back to 18. Sequence of Script Execution: sequence off the script when you are defining command inside off a script. If you want to run, command a command, be and you want the command be to run first. Then you should put command be first. That's how the script works. It goes through the sequence and start from the beginning, and it goes to the end. So if you have command one, 23 and so on, it will run the command one followed by two, followed by three. For example, if you wanted to run ls command first, put Ellis Command first in your script, followed by date and Kell, which is calendar. These are a few example commands I just picked. So if you want to run date command, the first thing, then you should move that up before l s command. That's how the scripting works. Any script that you run, whether it's a corn shell, poor old, any kind off programming language that you know, it runs this way in a sequence, something you should know. And ah, if you are confused that hey, I run if else statement. But if works this way and it runs else that way because that those are the statement scripts. We will cover that statement. Scripts Don't confuse yourself right now, but focus on this one script sequence it always 1123 as they are sequential in a sequential order. 19. Welcome to Basic Shell Scripting: Hello, everyone. And once again, welcome to basic shell scripting section. Okay, so this is the section we're actually gonna get into Creating shells. Gross. The basic cell scripts. How we could create jobs, how we could run simple, um, echoes scripts. Or how we could use input and output off our state mints to war with the shell scripts. So what are we going to cover in this section? So let's take a quick look. First, we will start by creating our first script. Yes. So this is the fun part. Guys okays first Shell script. You probably have written many shell script as well. Ah, and the basic one. It might be like, Ah, you know, like ABC for you. But that's OK. We'll start with always start with ABC. So we'll learn how we could create a first group. How we could execute and permission stuff like that. Then we will create a second script where we will run basic tasks like based on our regular commands. We will run our basic tasks followed by the basic administration Task Adminstration task Are those like if you are checking the disc base, our memory and how can we put that in a script that will do all that automated for us is in that fund that you don't have to log in any anymore. And then run those tedious commands everyday to check your system and see how it is doing. We will cover that in the lesson. Okay, then. Well covered the defining variables. You guys know already about the variables, right? How can we define variables in the script and actually use it? Input and output. When you run a script, it will ask you a question. And based on your answer, how is going to respond those type of question? Now, how does it work in the rial life? Well, if you notice when you run a script in Windows or even in Lennox and you installing a package or something, it will ask you question, right. Do you want to go ahead and continue? You click quiet and says Yes. Based on your input, it does certain functions. So that is about but output. Then we'll have condition statements. This is where it gets a little complicated. But don't worry, I am with you. That's what I'm starting with. Basic. Um, it's just like as if you are, Let's say going toe a war and you were in the military. The first thing they do is they actually train you. So this is the whole thing is about training. I wanted to start from scratch, so you know everything inside out. Then we'll have some additional conditions. Statement. But for the case statement and then four loops statement. Why do we need four loops Statements? What are the advantages offered? Do? Well, scripts will also cover the Doo Wah scripts, and the last one is getting online Help. What does it mean? Getting online help. Now, let me tell you this. I'm not like a I don't know every scripting, um commands. I don't know every scripting, um, variables inside a script. So sometimes I also go online and find help. So I want you to also utilize that same technique to go online and look for Pacific scripts that can help you achieve your goals. So how can we get those on my house? All explain it to you, so sit tight. Let's start or start, but are creating first grip 20. Create your first script Hello World: Hello World. Okay, Yes. This is the basic script that most of the time that I have seen people, right. Whenever there, star learning, scripting languages. So we're learning back scripting languages and the first script that we will write as to echo or toe output on the screen that reads Hello World. I remember when I was in college the first script that was given to be by my teacher and or but my professor was too right. Ah, script that will. I'll put print on the screen that would read Hello World. So anyway, I am going to do the same thing for you guys that I want you to create the first script. If you know this, how to create a script, awesome. But start with me. Let's go with me. So we're going to start with creating the first group that will output Hello World. So I have already my lyrics machine session open and I am logged in as myself. No, as a practice, as I mentioned before, that always create your script in a Pacific directory, so it will be easier for you to remember were those scripts are so let's do CD script I'll have already created that. You should have that too, if you follow my early lessons. If not, then go ahead. Run the command make de ir followed by the scrip. And it will create a script in the script. If you do ls minus. L you probably not gonna have anything if you never had a script before here. If you do. Ah then go ahead. And the lead descript the first script. All the lead is Hello world. This is permission denied. Why is that? It is owned by me. It is owned by my group. And I could remove it by looking at this. W it has write, write permissions. I cannot delete it. That's a good troubleshooting exercise as well. Right? Uh, I know it. Why I can't delete it occurs when I created the folder or directory called scrip, I was rude. So let's go. One step back. Cd dot dot Do ls minus l and you will see. Yeah, I was right. See? Right here says this directory is created by route. So anything under this directory will be protected by user route. Nobody could touch it or delete it. So the best thing I should do is to become route, go into my home directory, and I was simply removed the directory now, so this will start fresh. Okay, so now it's gone. That's exit out off that route. Make sure you are yourself. Yes, we are. You logged in ourselves also. You could check by looking at the prompt. It tells you the, um, name off the user logged in and the server name. So now we are in our home directory, and now we're going to create a directory called Scripts. And we will put all our script from this point on to our folder called Scripts. Now, make sure it is there. Yes, it stares the end, and now it is owned by me. Now, you don't have to run all the scripts as root. The only time you would have to run scripts as route if the commands that you are adding inside of your scripts required root privileges. Yes. So you could run any any command like PWD Ellis or anything that do not require root permissions. If you are running other commands, let's say ah d m I decode or d message or D f uh, dis command. Those are the type of commands a require route rights. So it's better that you run those commands. Ah, those scripts. Ah, you create the scripts as route anyway. So let's get into our scripts territory. And now you see a We don't have any file or any directory in our scripts directory. So we will create our first script and we'll call it Hello World and you could put dot bash as well. But since we will be working primarily with Bash Ah, Shell so we don't have to specify. Ah, the extension. So just simply, um, hit Enter. Once you are in the V I mode, you specify the shell. So we want to run this script as bash. Good second thing. Who is the author off the script? I will say it's myself. Then again, comment date Script is created. Let's pick any date. So let's say if you're picking zero a slash 20 sacks. 2020. Okay, um, Daniel put in. It's a little description description and that will read this script Will output Hello, world on the screen. That's it. Simply that if there are any modification so you could put a date modified and then you could put the date. Since we're doing the first time, you could just put it the same date as you put a did created. Okay, so our shell is defined. Our comment is defined. Do we have to add anything? No, it's just a simple script. So I will go ahead and write the script that were print Go. Hello, world. And that's it. Now you could just to escape out of fed and right. Quit. And your script is created now. Verified. Yes, the script is there, but you cannot run it. Why? Because it does not have execute herbal permission right here. So in order to, uh, a sign proper execute herbal permission, you will have to run the command change mod. Oh, plus execute herbal. Hello world. And by the way, I'm using tap that auto completes file. And if the ball does not exist, it will not auto complete as an example. Let's say if our instead of h e l l o put h A l l and hit tab. See, it's not gonna work, so it has to have a correct spelling. Okay, so we have modified the permissions. Let's verify it? Yes. Now it has the execute permission. As if you see as soon as we could give it. Ah. Gave it executed information. It's color change as well. Now, please remember, don't focus on the color, as I said earlier as well that sometime maybe you probably creating a script in Solaris or in a I X or in any other UNIX or links play were that does not give you that color changing scheme or that depends on the environment. A shelf. So that's why Just focus on that it is executed. Well, by looking at execute permission. Okay, now, perfect. Now let's run it. So again, you could run it through the hole, Pat, which is Absolute Path script directory and hello, world and hit Enter. And there you go. Your foot script is created. Isn't that fun? You have just created your first script, which outputs on the screen. Hello, world. Now what I'm gonna do is I'm gonna run the script as a relative path. Sadat slash Hello, world. There you go. It does the same thing, but it executes it with a relative path if you notice. Um, there are no lines in between on top and bottom, so I wanted to make it more clear. More neat. Look. So what I will do is modify the scrip. Hello, World hit. Enter. And now I'm gonna put one echo here and one echo here. So when I put these echoes inside that it will actually generate an empty lines before. Hello, Orland. After hello World and datemodified again. I could just put it like, Let's if you're modifying it a day after the first time you created then you just 21 save the script And now let's run it. Hello, world. Nice. You see? Now it is giving the output that you want Now as exercise I would recommend you to go ahead and create a couple off, um, scripts like that that will output on the screen Like my name is Imron. Absolute. I love to teach and I am whatever that you wanted to add, just I'll put on it, chop the lines which over the way you want it. This will give you some practice on how to creates him. Well, script 21. Run Basic Tasks Script: basic task rips. This is our second scripts that we will create together and this will actually execute some basic tasks, uh, that are, like, based on some basic commands. So the task that we will define in our script as the 1st 1 is P W D. That will print my working directory ls which will list all the files or directories in my current directory. Who am I? Um, it will print my user name that I'm logged. And with date the crunch date tell the current cat calendar and the last one I want to create it. Three files in my directory that I'm logged in. Ah, dead files are A B C. And the command we was used to create them is touch. So it's just that simple. And that script will run sequentially. If you remember, it will do. The 1st 1 is pwd than ls and then so on. So my machine is right here and I am going to create my second script. Make sure I am logged in as myself and wish directory on men. I'm in scripts directory. Perfect. That's the directory I wanted to be in. Um, so I will go ahead and v I a new file and the name off the file of a pick as they basic tasks. It's just that some and her define your show. Author. I'm gonna keep making you do that again and again. So you will remember Date created, Joe. Eight money, 20 description Run. Basic Lennox Tasks Date. What was this? Fort one? Tell me. Modified Yes. Again, You're not modifying. We just putting today's day and I guess that's pretty much it. Now, I always like to start my script with Echo, so it will be a new line. And this time I wanted to write down Echo. This script will run a few basic tasks. Now, remember, this is not a description. This will actually output on the screen. Then another echo just for a new line. Now what we want to do, we want to see which director we are in. So simply, just type P. W d. Okay, it did that. No, let's see if he could do ls who am I? Date cow. And the last one is I wanted to create three files A b and C, so that's pretty much it. It's gonna run 1234 by six commands six basic tasks. Core those tasks what exactly they're gonna do and go ahead and escape. Bottle fed and right. Quit Saved the file and check permissions there. No permissions assigned the permission. Basic tasks. U Unless my cell tr just to confirm you basic task has been created. Now go ahead and run basic tasks better. Nice. Okay, let's see what it is. Okay, so this script will run a few basic commands. This is the echo. Think that we added in right? Then the next thing we wanted to know which directory we are in, we are in this directory. Then l s L s will list all the directories and files inside off my exit current working directory. And those files are basic task and hello world. So it's this own file that I just run the command and then who am I? That's my name. I am logged in as myself date. This is the date. It's telling you what date is today and calendar. This is the calendar that is output. Now the last one is Hey, what happened to touch ABC? Did it create that file? I am sure it has. But why didn't you see in hair when it was listing that files? Very good question. Now let's go back to a sequence. Remember, the script works in a sequence in an order. The first thing first. So by the time touch ABC, it hit that touch ABC. It ran. Ls command before that? So that's why you didn't see it. So now, if you run it, you will see your three styles in there. So without running the script, just two ls minus l. And you will see in there. There you go. See you. See? I said I'll do ls myself to your ltro list everything in, um, in ah date format. When was the last created? If you see, it has created a B and three C files. So this is how we do our basic tax. So if you are going through all that hassle every day and you want to automate them through one simple basic tasks, you could do that to simply this way again. I like to keep things neat and clean. So what I would do is I will put echo in every line Cool co and echo and then at the bottom of us say echo, end off screen. Nice. Welcome. You guys probably knows hate in Ron just did something I didn't purposely I just put it down wrong, um, command And let's see what the era Messi comes up. Um, it's run the basic tasks, and it did everything I asked for. Now you see, it is it has given me those ABC files as well. And now at the bottom, it says Line 21 Command not found. Okay, so it's something went wrong with the script. Now, this is how you troubleshoot a script. I wanted to cover that troubleshooting help part right here at the beginning. Because every time you write a script, there is always, always a chance. I would say I'm not gonna say that very little chance. We are humans. We make mistakes. There's always a chance that you fat fingers some of the commander. Or are you make a mistake. Then script doesn't run. Then how do you troubleshoot? Well, the Lennox offering system or the scripting shells are smart enough to tell you where the problem is. So it's telling you that the script is this and in line 21. There's a command called E C H. That command now found You want me to run the command? I understand, But there is no such thing as command. Why? Let's try it just by simply typing. Yeah, there is no such command. So we know that in line 21 in this script there is a mistake and we have to fix it. And the way I do it his i v i the script and I will Let's say if I'm right here or anywhere , I'll just do Colon 21. This will bring me exactly to that line where it was complaining