[Autogenerated] And we're going to take a look at
processing output from commands.
Now, we've seen processing output from files.
But what about commands?
When we take a look at the last log command very often,
it's going to give us a lot of information about user
accounts that have never logged in.
So within our file, we can exclude those lines and perhaps other lines.
So here we're saying, don't show me lines where the user has never logged in.
Don't show me lines beginning with the user name,
that's header information we don't need and don't show
me information for the root user.
We then go into our main block.
We can increment a counter just as we did before.
But we can also implement if statements N F is a number of fields.
Now,
depending whether the user has logged on from the console or
whether they have logged in via S SS H,
it's going to interact or affect the number of fields in each line.
If it's equal to eight, we can choose what we want to print out.
If it's not equal to eight, then to be honest,
its going to be equal to nine,
it's going to have the address the IP address of the client,
we can go through then and print it out the fields
that we want to show with that done.
We can then go through to our end bloc.
We can print a summary line and then the text that we want to include.
Once we've done that, we can close our end block and we are done and dusted.
But of course, really to see this, we need to find it from the command line.
So that's exactly what we're going to see within our demonstration when we
look at processing the output of the last log command.
So we can look at the last log command itself and then an
alt file we can use to process that data.
Come on, let's find our command line.
Now, the first thing, we're going to take a look at the last log command.
This is a really useful command.
Last log.
When we take a look at it, the first output we've got is header information.
Now, if we're going to create our own reports,
we don't necessarily need that header information.
But also taking a look down.
The only user that has actually logged on,
on my system, yours could well be different.
But the only user that's logged in on my system is the user pie.
The user account that I've been using.
We can also see we've got the from column populated.
So this has been via SSH.
So we have the IP address of the client included.
Now, all of this is great information,
but because our screen is so clattered with data,
we're going to miss the important information that we might want.
So this is where we can start filtering our information a little bit.
Now, we have got a git repository, you might have cloned it already,
you might not have cloned it,
but we can provide you these files from the git repository if I go
through and just delete it for the moment R M minus R F.
So recursively deleting my seven an arc file file,
we can go through and run the git clone again.
I'm just going to use control an R and I'm going to look for clone and
we can see then that we've got the git clone command.
Now, if you don't have git at the command line,
you can also just put this into your browser http S git hub dot com
going through to the Urban Penguin set an arc git and you can
download then a zip file and expand that.
But let's go through and clone this again.
So that gives me the repository and inside of that repository as I go
through and take a look inside of the sd an arc directory.
We've got a last log arc.
Now we saw this from the slide but we can see we begin by selecting our
lines before the main block query actually saying don't show me
anything where users have never logged in with that text is included or
whether the line starts with the, where the line starts with root.
So we're not going to see anything with those three lines.
We've got our counter, we're looking for the number of fields.
So it's really going to be eight or nine and we're choosing what
we're going to display if we've got nine fields,
which I will have co I haven't logged on to the console.
It's going to be then printing field 165 and nine,
we then got our summary information, which is just saying what we've processed.
Now, we can start seeing then the difference.
So we know what the last log command is going to give
us and it gives us way too much.
Whereas if I now go through and pipe this output to AK and process my file,
so the lowercase F and we can go through to the last log
dot org file and then just hit enter and we can see now
we've only got that one field.
So my user account ee and the date that we have last logged on.
So we're including all of the time information,
just the information relating to the last date that they've logged in and the
number of users that have actually logged in on this system,
we can see it's just one user.
Now, if you've got a system that other people are using,
you're going to obviously see different information.
But if it's mainly your system and you're the only user account,
you're going to see something similar to this,
but you can test with other accounts log in as more accounts.
But we can see how we can get much more usable information by looking for
exactly what we want and storing that within our arc file.
So it's not all about processing files.
We can process the output of commands as well.
But come on, let's go through and summarize what we've looked at.