Let's keep on moving.
So we are going to create another script that will run basic administration tasks.
So before we had the basic commands that we wanted to create in a task in a script.
So now we wanted to run basic tests.
So our basic administration task and those basic adminstrations task and example I picked as the first
one is one top second one is D F minus H.
Third one is free which will check the memory.
By the way DFS forward to check that this base up time is to tell when was the last time system reboot
and system load iOS data input IO statistics.
So I'm sure you know these commands already.
If you don't know that it's fine you can look it up and find out what the command do.
But anyway these commands are there to check the system helped.
So when I actually joined my first company this is something that we were doing manually.
So every time a system administrator would come in they would run these commands on US servers and checking
the system held.
Are there any issues are there any space issue and so and so to learn somewhat of scripting at the beginning
I was like wow we could do so much about this and waste without wasting so much time.
We come and we spend like hours just going through so many systems and running certain commands so I
created the script call check script.
So that would check the system helped.
And it actually added so many things later on so many other commands that actually we needed as far
as by the system but anyway the point is that you could automate all those System Administration checking
type related task in a script.
So let's create a new script
and if we are logged in as our self and we are in our home directory and a script directory as you know
we have these two scripts that were created and then we have a few empty files that's fine I'll leave
them there.
The next script we have.
You want to do admin tasks.
So this is the name I picked you could pick anything that best fits the description of your task.
Go ahead and hit enter.
What do you do first.
You define the variable.
Yes.
An author who is writing this crap that as you and Mike has me of course then we are doing date
0 8 22 2000 and 20.
And we are doing description.
The script will run BASIC ADMIN commands or task whichever that you want to pick date modified since
we're creating the first time we could pick the same date Okay.
Perfect.
Now I will always like to do.
ATCO and say Is this script will run basic administrative commands that said this is how it's going
to come up.
Of course I want to do it here and one here.
OK.
Now what are we going to do.
We are going to run top command first.
I'll go again DBF mine's command second echo again.
Again as you know Echo is just to put an empty line so it'll look more organized up time.
Go IO stat and echo and echo and off script purrfect.
OK good.
Now let's go ahead and see it and assign the commission's and the name of the file was admin at that
desk.
Yes and that's it.
TR verify the permissions are given.
OK so now let's run the script
OK so it does run.
And if you'd notice really quickly it spit out the line where it says this is what the script does.
And now you notice that the SEC the first command that I want to run in my screen was top and now it's
now running.
Other commands.
Why is that because the top command is a command that will keep your session open and give you the status
of your process to use your memory in a real time.
So it does not exist out.
It just stays there.
So that's why my script is kind of stuck for it to finish.
So it could run other commands.
So how do we overcome this problem.
Well one thing you could do is you could tell the output of the command to be simpler or pipe it to
something else.
So this way it will run other command.
So how can we do it that's do quit.
And you see as soon as did get out of this sorry as soon as I did quit out of top it did run all the
remaining commands.
But of course we were stuck there and we didn't know what happened.
So what I'm going to do is we will log back modify the script again and the script name was at Muntasser.
And this time what we can do is we are going to say that when top runs just give me the first 10 lines
that's fine because mostly the top part off the top command has the most important and one which gives
you the information about memories you process seems important.
Most processes that are taking up most of the c.p.
So I'm going to put pipe to head at minus 10 and then we will run that command again script again.
OK so let's run it now.
Admen task enter.
All right see.
It kinda gives you can wait for a few seconds and then I'll give you everything because it was processing
and now it gives you from here this script will run basic administrative task and those tasks are the
first one is top and the top is giving me the first 10 lines.
Then it it runs D F minus H Kevin which is giving me the output up to here then is running free.
Free is free minus M As for the memory information to include free.
No actually if you forgot I was looking for free and it was not there.
Anyway we'll add that the next command that it was running was up time and uptime is right here and
the system been up 47 minutes and the last command it ran was iostat which is right here.
And the last thing we added was and so of course we missed the VI missed a free command that's fine
we'll go ahead and add that.
And and it was after D minus H.
So at go free minus m here and now I added the missing command that we wanted to run.
They go so it see it get worse.
Yes it is right here the city output off free minus.
OK.
So this is how you run the basic administration task you could actually also filter out this output
to through a pipe and you could view anything specific that you wanted to know about this output.
So what happened was in my beginning years when I joined my first company and I ran this when I created
this check system script what I did it eventually it was drawing up so much information that we really
didn't need it.
So we modified it filtered out a lot of output that was coming from these commands so you could do that
too depending on what exactly you were looking for.
My recommendation is to you is go ahead and create a couple of scripts that will run your basic administration
task and see how they run.