OK so we have discussed theory so let's write some script grade file.
I pleaded as age and on the first line start vade siobhán been Bash.
Now your target is to provide one word or a sentence
as an argument.
To discrete
if in that sentence
there will be IP address.
Find out
if that IP address
is reachable or not.
That means dead.
You need to create a script which takes 1 hour of Blooms-End.
And if that argument is some very present IP address you need to find out if that IP address is reachable
or not
as need exactly one argument.
We can start with that argument check.
So if they are sign Hesh which means number of arguments if it is not equal to them then we can print
ICO provide exactly one argument.
E.g.
the lot of Sanzio which means our escape name and somebody who meant we can also exit with stutterers
of Amina.
Now we can assign first argument to variable Cold War One
and we can now write a regular expression for IP address.
I will also do some comment here.
IP address rhetoric's
So we know that IP address has four part of digits divided by default.
And I think it would be best to write some example here some example of IP address
that is good to know that each part of that IP address can have one up to three digits and digits only.
So first part in the first part we have range 0 2 9 and it will be repeated one to three times.
So I will put one commissary into curly brackets.
Then we have a dot but dot is a special character which means any character so we need to use backslash
before that.
And by that we are telling that this is only Klesko normal dot without any special effects.
Now we can continue the second part which is same as the first one and the same you can do also for
search.
But
so we're in 0 9 and then repeat one to three times
for the fourth part.
We can also instead of orange in square brackets use special character class gold digit.
Discuss with prisons any number and we will also repeat these digit one to three times.
And now we can finally do some regs check to see if indeed argument is IP address provided or not.
So right if an inside square brackets of right where one equals sign
and after equal sign deal done
and our variable that regular expression.
Now we are basically asking if IP address is found and if yes do something.
But that would be to ask immediately if IP is not found.
And in that case it's in disarray.
So for that reason I am putting exclamation mark before square brackets.
Basically I'm doing negation.
So if there is no IP address found we can bring the users ICO.
No IP address provided.
And we can also exit the status to
now if the script won't be exited here.
We are sure that some IP address was found and would be good to store it into variable for example IP
for that we will use for that IP address.
We will use beshe rematch 0 do remember do remember understory I told you about that as they're very
much zero Michie's all those regs we have to specify and be careful how you ride bansuri much as there
are bought Kirtley and square brackets.
Now we need to find if that IP address is reachable or not.
How to do that.
Beeville use Bing.
Come on.
I will firstly write some comment find if IP address is reachable
or not and on the next line we can do basic common
vowed I have here read text which means that something is wrong.
And yes I have mistake in if statement.
I didn't use dollar sign before the rebel so I will just fix it now and we can continue with Bing.
Come on we will ping four times our IP address.
So I really will spin the barometer.
See.
And that barometer C means how many buckets do we want to send
now.
If that ping command was successful vivo assign to variables that those some the message.
So if it is that is zero then we assign it to status variable message alive.
And if ping was not successful we will assign it to that those message that are not reachable
and to now we can print it go
I'd be fine.
And if you specify our IP address us are assigned IP and in parentheses we put our status as the status
of that IP address
we can safely descript
and Grant executive permission we can descript to create one and
all I forgot to properly call descript.
So once they Murra
integrate no IP address provided it works perfectly.
I can try now without any arguments and great.
I have a message to provide exactly one argument.
Now I can try with two arguments and we have to provide exactly one arguments.
Great.
Now let's put as an argument you are a computer localhost IP address and we see the pink output and
at the end we have message IP from the stutterers alive.
Great but I don't like to see that pink output.
Last sentence will be enough.
So I think that we can go back to our script and we will redirect standard output display to screen
to Dev-Null.
So after being command right to him which means standard output and every day the NSA agreed to Dev-Null
thanks to that we won't see any big output.
So let's try this out.
But now as an argument I value some sentence which can represent for example one line from a companion
document with IP addresses description.
And of course if you need to find out if IP address is present here and if it is reachable
so I have specified songs and then with IP address in it
and we can round it and grade b c i be found and it is alive.
So now we can change the sentence to something else and mainly change the idea that has to be not reachable.
Now you need to wait.
And as IP was found.
But it but it is dead not reachable.
Maybe you don't like to wait so long for Pinga to spawn so you can change big barometer of see and then
running again.
So after a few second we should see the exact same response.
That IP was found and it is dead.
So we have now learned how to use regular expressions in our scripts.
And I will wait for you in next lecture.