OK let's look at this next lesson about directory assignment.
What are we going to do in directory assignment what kind of script are we going to do.
Well this is a script also.
I have experienced many of my coworkers or my friends who are in this field they have experienced this
kind of issue.
What happened is they there are home directories or there are directories inside of slash home.
But what happened is all those users that are in the Etsy password those directories do not belong to
them.
So why do we have those directories and if they do not belong in Etsy to any of the use of that are
in ETSI password because in reality as a standard every user directory should go in to slash home and
if there is a directory that is like x y z and it does not belong to an actual user should be deleted
from slash home unless it has an application associated with it.
Or you know there's a business justification for it.
So we are trying to find out those home directories that do not belong to a user.
So we will do is we will match the users from as the password to slash home directory and it will complain
hey this directory do not belong to this user or has no user at all.
OK so let's go into our machine.
Now this time I want you to be root and first of all what do you have to do is to go into the slash
home directory and create a user directory called Juno's.
Now Junos is a directory named pect because I do not have Junos in my Etsy password.
You see nothing came up.
It means this user do not exist.
So if my script works the way I want it to work then it should complain.
Hey Junos is a directory in slash home that directly do not belong to any user in ETSI password.
So want to know that.
OK so how do we do that.
Let's get into a script and I want to create that script in slash temp two-CD slash temp and do V-I
check Diyar does the name of the script that we will pick and we will define our shell and our author
who's the author that's you date
description.
This is the best part.
This script will find directories Bedacht uses modified 0 8 8 Touzet 20 20.
OK now what it will do it will first go into CD to slash home.
I want to run this command.
Then we'll put a statement for and I will put a variable this time DJR is just a variable.
You can pick anything again an asterisk.
So I went to C-D slash home directory and I am looking for all the directories and I'm putting all those
directories into a variable called DJR.
Then I want to do is
create another variable and I'm going to call this variable C-h k check equal dollar parentheses which
is right above number 9 crep minus C
from d r.
Sorry this is a variable we have and agast for
let me read the script and I will explain you once more time what I'm doing check is equal or greater
than one
then echo.
You don't have to put code if you don't want to.
Sometimes I do sometimes I don't.
It really doesn't matter.
Directory is signed to a user else
directory is not assigned to the C does it.
There's a script I wrote No let me explain you again.
OK so what is script is actually doing.
Is it spining all is going into the home directory and is finding everything in the home directory and
putting into the directory tree which is a variable then what is doing is defining another variable
and another variable what it's going to do is going to run a command grep it minus C option which will
do the count if it finds it 1 or 2 or whatever and it's going to grep from this list which is in this
direct and this variable and it's going to grep from at c password.
And if it finds even one directory that has a user that's what I said if check is greater than 1.
If this variable returns anything more than zero which is check is greater than 1 then echo directory
is assigned to a user.
If it is below 1 then it's going to say else directory is not assigned to the user and fee and done.
So we will run the script real quick.
And I want it to assign the permission.
Now let's run it.
OK.
Now you'll see it says I have Zoll.
So basically what before I tell you the output.
Let's go to home and you will see there are 1 2 3 4 5 6 directory's are in at slash home and now it's
going to grab up all the six directories from Etsy password and is going to see if that matches.
So this is I have Zoll is assigned to use a perfect Junos is not assigned to a user Peter's not assigned
to use the test is Test 1 2 3 is and test 4 5 6.
So basically that's what I'm doing.
Now what I could do is I could simply if I run the script and I could simply do crap and I'll do not
and it will only give me no such check ups I am in.
And so now check
I think I put it in
check.
I'm putting a slash root directory to check Deodhar.
And when you hit enter and now when you do up not I will know that these are the two users that do not
have a user account and their directory is there.
Why is there that's a problem.
That's a security risk.
So now I could simply go and delete it or find out who these users belong to.
Also what happened is that's a real live example what happens if if you have a group of people and one
of your coworkers leaves the company so you delete his or her account.
But somehow when you delete it depends on which command you run the use or delete.
It does not delete the home directory with it.
It keeps the home directory unless you specify and they use a delete but the option I believe is dash
dash or move then able to remove the direct.
Otherwise it will not.
So that's why you have to come in and do some of the house housekeeping and make sure all those directories
are gone.
So that's how it works.
Try it it's it's a very useful script and you will need it one one way or the other whatever that you're
doing or if you are trying to look for other things you could just change the script the way that you
want to use it for.