Script schedules and notifications.
Now we have a few scripts that we already Rondo's are just full of valuable scripts.
Now we need to schedule them.
And how do we need to schedule them schedule them through the cron job a cron job is a process an automated
service in Linux or in Unix flavors that you could specify scripts to run at a certain time and then
we can notify the users or administrators engineers through the email that this group ran and they heard
the output of the script.
So this is something that you probably already been doing or as you might have to do when you are in
corporate environment when you create shellscript then you need to make it more automated.
What I mean is more automated meaning you automated a script to perform certain task right now you go
one step further but just to schedule it so you don't have to run it yourself.
OK that's a second step of automation.
The third step of automation is that you.
Once it runs it what do you want it to do.
Well you wanted to either have a file created or do something or you could just it could this script
could just Nordic by a cron job could just notify the system administrator.
So this is a few steps you will take we will use this.
This lesson is based on our previous created script.
So I log into my Linux machine right here and I am logged in as myself and which directory I'm in.
And my professional scripts directory and the script that I will used to schedule is paying script all.
So when you run the script it actually Pang's an IP address that is Pingu they will say OK if it's not
Pingu will say it's not OK.
Now you can run the script and view that result on the screen.
Right.
But if you want to schedule it so it will run itself and it notify you.
You have to specify that cron cron job.
So first make sure you have the complete path
piece paying Desch.
OK.
So this is a complete path.
Copy it so you don't make any mistake while you are creating a cron job.
Now type Crohn before you type Crohn type data so you will know what time you want to run at this time.
It is 2031.
I will schedule it for twenty two point thirty four for example.
So if I do cron tab minus E is to edit.
So the first field of Crohn and I'm sure you are familiar with it is the minute.
So I want to pick the minute 34 and the hour is 20 and the day of the month we're on the run it every
day month of the year every year and day of the week.
Every day of the week.
And now the commands so hit right click and it will paste your script so it will paste.
Now how do you know it ran.
You could just output to a script ping output.
So this is the output from the from the script that will run.
And the reason I'm putting ping dash up was this way you would know that the script did run.
So that's save that cron is 2034 Dessa time it'll run.
What time is it right now 2032.
So we actually have to wait what.
One minute and now is 2033 So in one minute the script will run.
So you will see we have a file name called output dash error so don't confuse with this one the file
that will come in will be output.
What was it.
Well put.
The ping dash output.
So this is the file that will spit spit out my script and the different variables are specified.
Now as we wait for the script to run the next thing that I will Khowar is about the notification.
Now how do we notify a user through the e-mail.
Well you could actually take that file that will be created which is paying dash output.
You could create you could take that file and send it to the user.
Right you could do that.
But then you have to kad the file and send it.
But how about we just simply instead of going into panga ash Uppal file we'll just specify the name
Osaki The e-mail address of the user that is going to.
So that's that that's what we will do on the second step.
So let's check again what time is it right now.
It's 2034.
So the script has already ran Let's confirm and
it did not put the output is
paing put
saying put.
Where did it.
I think it's probably putting it into my home directory.
That's probably it as.
Home of Sol paying outputs.
Yes see that's what if I wanted to have this output file to be in that exact same location where I want
where my script is then I have to specify the full path the absolute path.
But since I did not specified by default it will put in to the user's home directory which is home.
I have thought so now anyway.
Let's go one step back.
This is my home directory check and at the pool is paying Dasch output.
And you see it is there when I wonder what is OK and is not OK.
Anyway so that's how you could schedule your scripts and it becomes so much easier when you actually
rely on an crosstabs.
Now next one is the notification.
As I said you could cat out the file and send it over to another Crohn.
But why you want to do another cron.
So what you do is you go back to Crohn tab fantasy and now instead of running it to ping output what
you could do is you could pipe it and do mail minus.
As for subject
connectivity
status this is this is going to be a subject.
And where is it going.
It's going to my e-mail
and that's pretty much it.
So if I schedule this for a time that is right now or two minutes from now it will run but it is not
going to e-mail me why.
Because the e-mail relay server is not configured in my server.
So if you already have e-mail configured in your Linux machine and it is able to send out e-mails outside
of your environment then it will work.
Definitely work.
But in my case it's not going to work it's just the example that I'm showing you this is how you could
notify the juice.
So try that at home.
Try to schedule different scripts that he already created in the previous lessons and see how it works.
You could also output to a file just to confirm it works.
Well just save it an X.