[Autogenerated] In an ideal world, we would do everything from arc.
So we don't need to call axiliary programs such as sort to show how we
could do that and have everything within our arc file.
We can create a new arc file.
Remember these arc files are available to download
through the course repository.
We can run our first search here.
We're looking for our root user and we're populating an array,
the array, we're calling IP S IP S and its being made up of our field 11,
the IP address, this is an associative array.
So a key name having a value and we're just setting the value through to one.
We're more interested in the IP address,
not the value that we assign to the aso associative index.
We close off our main block and open up our end block.
Now the end block is going to run once we've processed all of the entries,
the heavy lifting really starts here with our end equal.
So we're assigning a variable end by going through and using a sortie.
Now a sort is just an internal function in an org using internal functions.
We don't have to rely on external commands and we can
reduce the load on our system with a sortie.
We are sorting the indices of the array IP S.
Now with this, we've got our associative indexes,
our associative indices if you prefer and we are sorting on those,
each entry is going to be an IP address.
So we are sorting on the IP addresses,
the output we are sending to the sorted IP S we then go through our four
loop working on I being one until I is less than or equal to the number
of indices that we have in the variable end,
we increment our index count to make sure that we do move on to the next
entry and we print out that entry from our sorted IP S array.
Now remember this entry is just going to be the IP address.
The IP address is the index that we are working on
in our IP S or our IP S array.
So we don't have to worry about deleting any duplicate entries.
Once we finish with our four loop,
we can close it and we can close off our end block.
Then it's a matter of moving out to our command line and
just taking a look at how we can do this.
So how we can do our sorting inside of AK and we can
begin by sorting our root log ins.
Once we've done this,
we can move on to sorting our failed login for invalid users and
combining it together but let's just get this working to keep it
simple and look at this back on our command line.
Now, let's begin by just making a copy of the arc file that we used before.
So I'm going to copy my simple dot arc through to and we can
call it SSH dash root dot org for the moment.
Now,
these files are also available through our git
repository associated with this course.
Now, if we go through and take a look at editing the SSH root org,
we can see the color coding is not so good.
I'm using a dark background.
If I hit escape and colon and then set background equals dark,
I'm going to get better syntax highlighting.
So this is better,
you can probably see the code just that little bit better
and we're going to start building this up.
So to begin with, I'm going to remove the search for the invalid user.
We don't need any of this and we can begin with our failed password for root.
Now, with that, we can see then that we are printing dollar 11,
but in fact, we don't want to print field 11,
we want to populate an array.
So let's go through and set this up if we have IP S that's the
name of the array that we are going to create and we're
going to populate it with field 11, which is going to be the IP address.
Now, this is going to be the key or the index of the array.
It's an associative array.
So its using the key name rather than an index number for our value.
We're just setting the value to one.
To be honest, we don't really care about the value,
but we're just setting it through to a value.
So we've got an array called IP S.
We've got an,
an element that is going to be based on the IP address with a value of one,
we can close off our main block and then open up our ending block.
Now we know with the ending block,
we wait until we've processed all of our entries.
So our IP S array is going to be fully established.
We can go through then and populate the variable end
to equal the value of a sortie.
Now this looks a little bit strange.
A sortie is a function, a function in built into our org program.
It's an ascending source on an index.
That's where a sortie come from.
We're going to then sort the IP S array.
Now remember the indexes or indices of that our individual IP addresses,
we're going to send the output through to our sorted underscore IP
S array and then we can close off our function.
We can now loop round each index within the array.
So using our four loop,
we can go through and specify that we start on the value of one,
our first element in the array and then move through until I is less than or
equal to the number of indices that we have in our array.
Of course, we do need to increment our counters,
our IP plus plus, close it off, then the arguments for our four loop,
open up our brace bracket.
So we know then all of this is associated with our four loop and
we can go through then and print the sorted IP S array and the
index that we are currently working on.
So we're going to start on our first IP address and we're going to carry
on through until we've got no more IP addresses left.
We can close off our four loop and close off the
brace bracket for our ending loop.
And there we have it a little bit more complex than we've looked at before.
But this is going to give us so much functionality all in building
into org without reliance on any other commands.
So if we go back and just take a look,
we can go back to our journal C T L command.
And if we reference then our new file S S error root dot org,
we can go through there and see that we have got a sorted IP address list,
we don't have any duplicate entries.
So this is then looking very good out of interest.
Again,
we might as well go through and count the lines of output to work
out how many people or how many individual IP addresses have been
trying to log on to my system as root and as we tally up that
total with the word count.
We can see we've got 100 and 12 lines,
so 100 and 12 unique IP addresses that are trying to
log on as root after 27 hours.
That's quite amazing.
But of course,
we've still got people trying to use invalid user accounts and we need
to look at including them that's up straight away.