OK moving on to the next lesson we have status on the total number of files.
So basically we're going to have a script that will send alert if files are less than 50 or whatever
the defined number falls.
So this type of scripts are often used in corporate and wireman when an application generates a few
number of files.
And for the developers or human system administrators they have to make sure doors file are there before
they actually go and run another workflow.
So if the number of files are 20 Go ahead run the workflow if it's 19 the work is not complete it's
waiting pending.
And then once it's complete notified so these type of workflow or entire process depend from one to
another.
So this will be co-heir what what we will run here is simply we will run ls command mysell option because
it will give de-listing but different options.
If you want to like LS LTE or just t or any other option that will give you the entire listing off your
directory then we will create a script to perform that comparison.
And of course at the end schedule and notify if you have to schedule it through the cron job and notified
through the e-mail.
So that's the two main way to schedule the job and to notify users of the e-mail.
So let's go into our main lab the machine.
I have already logged in as myself and home directory.
Let's go to the directory and I will create this group real quick.
So let's call this script.
You know what before we call a script so let's create files so that we can run the script against those
files.
So to create the file will create instead of 50 I'll create 20.
So touch file and of course I want to have 1 through 20 and let's call it text so I want to create files
from 1 to 20.
That ends with text.
Hit enter and you will see I have files from file 1 all the way through 20.
And as Doug textfile so my script what it will do is whenever it runs it will verify if he has a total
number of 20 files in my home directory and if it does then it will notify the user Hey I got the 20
files go ahead and start your workflow.
So to varified you do ls NSL command and do file an asterisk and you will get all the 20 files.
But now we have to do w c minus L to check the count count is 20.
Now purrfect Now let me put that script a little command this one in our script.
It's a small tiny script and we will run that script.
So count files is the name I want to get my script
and you're defining all parameters up.
There are settings.
There that day
description.
This is one of the most important one.
This script will
verify total number of files are modified
by the way.
You could also add any of the comments you want that will actually make you understand what the script
is for you could also give comments on every line and after you write something.
So let's say if you are defining a variable I'm going to define their variable here a equal or less
minus l file.
Esterbrook C might as well close.
So I have defined variable a.
So I could put a comment here if you want to comment defining variable a.
That's it.
If you want to actually do
if you want to actually add comments in every line so our variable is defined so what we'll have to
do is if
dollar a is equal to 20.
Now we are using e cube because we're using integer and you remember when we use equal equal sign which
is
equal equal when actually using the letter so putting why or no.
Then we put equal equal.
If a is equal 20 then echo.
Yes there are dollar a philes meaning 20 hours else go files are less than 20 because now redefining
it x actually number would be looking poor so we can put our variable here fee.
That's pretty much that simple let's put if here so come in line.
So let's give it executable a mission
code files and let's run it.
It says yes there are 20 files that as perfect.
Now what we have to do I could show you real quick if first of all before I show you something else
let's change it let's delete one file.
So one remove file 20 Tex.
Now when I run it it will tell me count files files are last and OK.
So now we know the script works.
Here's another quick thing I want to show you.
You see right here we always define variable here.
Right.
And a variable is a equal but the variable is what you could also do here is instead of just defining
a variable you could also actually put this entire
command here so you could do like take AUPs
this command the Cueto comes out it is equal to 20.
Then do that and then you don't have to define the variable you just commented out.
Let's see if it runs
Yes buyers are less than 20.
If I create back the files touch or more file 20 to 60 and now when I run it.
But yes there are there are files yes there are files which one is.
Remember you have that variable in there that's why I couldn't write here.
Yes there are.
And it doesn't understand what that variable is because we are commented out the variables so we could
say is there are 24 if you want.
Anyway my point here is to explain you that you could define variable which is the best way and cleanest
way to put your script together.
So you would know where to use your variable.
If you do not want to use variable you could also put that entire command inside of if else statement.
So that's how this works.
And once that is completed you can also send a message and return status to another workflow.
Hey the command ran successfully.