1846453 Members
2725 Online
110256 Solutions
New Discussion

Finding user script

 
SOLVED
Go to solution
Mike_305
Super Advisor

Finding user script

Hi,

Does anyone has script that I can run to find out or search for a users on mutiple system. Thanks in advance.

Mike
If there is problem then don't think as problem, think as opportunity.
13 REPLIES 13
Rodney Hills
Honored Contributor

Re: Finding user script

Do a "man rwho".

rwho works like who, but can list users on multiple systems.

-- Rod Hills
There be dragons...
Sridhar Bhaskarla
Honored Contributor

Re: Finding user script

Mike,

If you want to look at the users "logged" onto the other systems, you can use the command rwho or rusers. But you should have rusersd configured in /etc/inetd.conf file.

If you want to check each system for the users configured on the system, you would need to have remote access on the system through either SSH or REMSH.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Mike_305
Super Advisor

Re: Finding user script

Hi,

No, I need to search through password file to find if they exist or not.

Thanks,

Mike
If there is problem then don't think as problem, think as opportunity.
harry d brown jr
Honored Contributor

Re: Finding user script

rwho presents a security risk, and of course it's not going to tell you if a user is using two different logins.

live free or die
harry
Live Free or Die
someone_4
Honored Contributor

Re: Finding user script

Sounds like you just want to go though and find the user in the password file not find out if they are logged in or not right?

If you got your remsh set up on the systems.

you can do

remsh serverA "grep user1 /etc/passwd"

and that would give you the line for user1 in /etc/passwd in serverA.

Richard
Sachin Patel
Honored Contributor
Solution

Re: Finding user script

Hi Mike,
You mean you want to see taht user entry is exist on passwd file on remote system?

You have to run remsh for each system and grep for that user in passwd file
Here is simple loop

for i in sys1 sys2 sys2
do
echo $i
remsh $i cat /etc/passwd |grep username
done

Sachin
Is photography a hobby or another way to spend $
someone_4
Honored Contributor

Re: Finding user script

Awww good one Sachin!! A loop here is what I would use.

Now in this example hotnames.file is a file that has a list of the hostnames that you want to check. And we can do the grep with -i so the grep on the username wont be case sensitive.

#!/bin/sh
REMOTES=hostnames.file
for REMOTE in $(cat $REMOTES)
do
echo '#####################'
echo ""
remsh ${REMOTE} -l root "hostname,grep -i username /etc/passwd"
done


Richard


SHABU KHAN
Trusted Contributor

Re: Finding user script

Mike,

If you have ssh configured across your servers then even easier...

ssh hostname1 '/usr/bin/grep username /etc/passwd'
ssh hostname2 '/usr/bin/grep username /etc/passwd'
ssh hostname3 '/usr/bin/grep username /etc/passwd'
ssh hostname4 '/usr/bin/grep username /etc/passwd'

You could put a for loop around it too (see Sachin's example replace remsh line with ssh line)

-Shabu
Sachin Patel
Honored Contributor

Re: Finding user script

Thanks Richard
I didn't know that you can do like
for REMOTE in $(cat $REMOTES)

I does
cat $REMOTES | while read line;


Sachin
Is photography a hobby or another way to spend $
Mike_305
Super Advisor

Re: Finding user script

Hi Guys,

Thanks Richard and Sachin. I had something like this was in place but your loop is nice.

LINE=`cat mike.list1`
for i in $LINE
do
remsh $i hostname
remsh $i grep -i 'will' /etc/passwd
remsh $i grep -i 'wast' /etc/passwd
remsh $i grep -i 'schve' /etc/passwd
done

Mike
If there is problem then don't think as problem, think as opportunity.
someone_4
Honored Contributor

Re: Finding user script

Good Evening !!
Mike,Sachin
come on guys lets rememeber we are living in a unix world.What does that mean to us? Well it means that to every "one" way that we know to do something there are probably 1000 or more ways to do the same thing. I would be willing to bet that Mr. Jrf or Mr. Clay could turn our 5 line script into a 500 line script just for fun and give us the same result.And I am sure they could just as easly put it in a one liner once again with the same results.

Why am I ramblin on? I dont really know maybe cuss it is 10:30pm and I am on the forum and have nothing better to do. Is this what being single and 26 all about?lol

Back to my point. Yes I have a point. There are so many ways to do the same things. And that is why we are all here to LEARN. That's whats its all about my friends.That is one of the great advantages of this great resourse we call the forum brought to us by another great resourse that has changed the world forever called the internet. WOW what a gift. The power to interact with your peers all over the world 24 hours a day 7 days a week in a choosen profession or intrest.Isnt life great?

Well I am done for now. Gotta go get me another beer.

Richard :-)
Mike_305
Super Advisor

Re: Finding user script

Hi Richard,

Thanks to all of you for your quick reply. Every one was great. Thanks to all of you and Richard just for the last reply I gave you 10 points because you were up at 10.00 pm. Once again thanks for your help.

Mike
If there is problem then don't think as problem, think as opportunity.
Brian butler
Frequent Advisor

Re: Finding user script

Felt left out so i had to post somthing

wc /etc/passwd

will give you an output of three diffrent numbers like



56 245 3456

56 is the amount of lines in /etc/passwd file

245 is the amount of words in the /etc/passwd file

3456 is the amount of characters in the /etc/passwd file

oh yes and it just so happens that the set of numbers to the far left the 56 indicates how many users accounts you have on that particular box, well at least i think so
Reboot and give me twenty....