Being assistant administrator,
you're going to have to do a lot of different tasks.
So it's very important
to be able to automate these tasks using scripts.
So we're going to go through it in this walk through
of how to customize first, our environment
to make it productive for the scripts that we want to run.
So the first command we'll use is environment command.
This is going to give us a list of all the variables
relative to our environment.
The one we're going to focus on here
is the history size, just for an example.
Move towards the top.
So you can see the history size is 1000,
meaning that's going to store the last 1000 commands
but we're going to change that.
Now, another way to view variables,
is just use the dollar sign.
I'm going to use this command, echo.
And it's going to tell us exactly
what the value of that variable is
because how the variables are set up are key value pairs.
So the key is going to be histsize,
the value is going to be 1000 and we're about to change that.
We see the history.
We see we have a lot of different commands.
So in order to change the variable,
we're going to use the export command.
Now we're just going to use a low value
just to make the demonstration easier.
So just going to run a few commands.
We're going to do echo one.
All right, so if we scroll up with our arrow,
we see we only stop at three,
'cause clear is also a command, right?
So, one, two, three, four, five.
Can't go anymore than that.
So test that out.
So next thing we're going to do, we're going to make a directory
to actually hold our scripts.
Okay.
And I have a script currently in my directory.
We're going to move it to the scripts folder.
Okay, going to do sudo,
since it's in the root directory.
Make sure they went there.
Now, one thing that's important to note,
we need to change the permissions on here
if we're going to execute this script.
So just going to do a change mod really quick.
Going to do 775 right now.
All right.
Now, one thing we have to worry about
when we're using scripts is the path variable.
So the path variable lets the system know
where are these commands located when you just type them up.
So for example, when we type in just clear or last log,
these commands are stored somewhere.
And in order for the system to know where it's located,
we must set that in our path variable.
So first let's just see
what our path variable looks like now.
It's going to be a list of multiple variables.
So these are all the possible locations
that Linux will look to see how to execute that command.
All right, now to change that for us,
we're going to look at our bash profile command.
So we're going to vim.
All right, so we need to export this path.
And we're going to make sure
that we include the current variable.
And then we're also going to add the scripts
'cause that's where the script
that we just moved to the scripts folder is located.
So by the end of this,
we're going to be able to type echo.sh
and the system's going to know where to locate it
and how to run it.
Okay, now one thing we must do is use this source command
and that's going to pretty much reload the bash.profile
so the system knows to re-look
at the new configuration file.
Okay, now let's look at the path variable now.
Okay, now we see what's added at the bottom.
You see after the last colon, we see a /scripts.
Now let's try that bad boy out.
Do echo.sh.
All right, well we see that went through successfully.
Again, that script simply just prints out different lines
just for the sake of the example.
So if you want to check it out, see what it looks like,
you just do cat.
And you see that's how a script looks.
And again, if you just look at the lines
after the first one, where you see echo commands,
just print out things
and then see that the system will run it
just by typing in the command without anything prior.
Now the last one we'll go over is how to create an alias
for a lengthy command that we typically use.
So for example, I'm going to use this last log command
which shows the last login for all the users.
The tail, meaning that we're going to start
with the second line
and we're going to sort it
by the first line in alphabetical order.
Okay.
Typically we have the header at the top,
the username and the time,
but we just want the information
so that's why we started with line number two.
And we see this in the alphabetical order
based off the username or process.
Now we don't want to have to type it all the time.
So what we can do is run a change in our .bashrc file.
If you look at the last section
as user specific aliases and functions,
that's where we're going to input that.
Type in alias.
Going to name it ulog.
This where we're going to type in the command.
Again, we must run our source command.
All right, now we have reloaded that configuration
and now let's type it.
And you can see the alias ran the full command for us.
So we just walked through a quick way
of how to set up our shell environment
to make scripts and alias for different commands
to make it easier for us to run
and make our jobs easier as system administrators.
Thank you for sticking with this walkthrough
and I'll see you in the next lesson.