LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-14-2009, 07:40 PM   #1
shorte85
Member
 
Registered: Mar 2009
Posts: 47

Rep: Reputation: 15
Number of users using /bin/bash


I'm trying to currently figure out the number of users using /bin/bash as their shell to login into the crux. I think I have the right command, but I'm not entirely sure. I was hoping someone could look at the two different commands I have and let me know if it's correct or possibly point me into a direction?

The first command I figured out (or I think so) is this one:

Code:
$ cat /etc/passwd | grep -c "/bin/bash"
4314
Then I have another version of that command that I put together which was:

Code:
$ grep -c "bin/bash" /etc/passwd
4314
As you can see they both come out with the same amount. But I guess what I'm trying to figure out is if that is getting what I'm trying to figure out, which is the number of users who use /bin/bash as their login shell in crux. I think both work correctly since both commands give me the same amount, but I guess I'm a little weary of it because I'm not sure if it's giving me the number of users who use /bin/bash as their login shell.
 
Old 03-14-2009, 08:14 PM   #2
AsusDave
Member
 
Registered: Jul 2008
Distribution: Debian, Ubuntu 10.04
Posts: 151

Rep: Reputation: 34
I think either command will work for you.

The result would be the number of users that use /bin/bash for their login shell.

HTH
Dave
 
Old 03-14-2009, 09:33 PM   #3
shorte85
Member
 
Registered: Mar 2009
Posts: 47

Original Poster
Rep: Reputation: 15
Thanks Dave. Now I'm stuck on something else. I'm working on pretty much the samething, but now I'm trying to figure out what the second most commonly used shell program in crux is. I figured using the same command would work by adding a * at the end of /bin/bash/* but that doesn't work. It just gives me a 0. Like this:

Code:
$ grep -c "/bin/bash/*" /etc/passwd
0
Not sure what I'm doing wrong. Maybe I'm not using the right command. Hmm, lol
 
Old 03-14-2009, 10:27 PM   #4
nflenz
Member
 
Registered: Feb 2006
Distribution: CRUX 2.4
Posts: 96

Rep: Reputation: 18
Quote:
Originally Posted by shorte85 View Post
Thanks Dave. Now I'm stuck on something else. I'm working on pretty much the samething, but now I'm trying to figure out what the second most commonly used shell program in crux is. I figured using the same command would work by adding a * at the end of /bin/bash/* but that doesn't work. It just gives me a 0. Like this:

Code:
$ grep -c "/bin/bash/*" /etc/passwd
0
Not sure what I'm doing wrong. Maybe I'm not using the right command. Hmm, lol
How is /bin/bash/* going to match any other shells? If you want to count all entries without bash, use grep's -v option. Otherwise, just change /bin/bash to a different shell like tcsh.

Code:
$ grep -vc /bin/bash /etc/passwd
$ grep -c /bin/tcsh /etc/passwd
 
Old 03-14-2009, 10:55 PM   #5
shorte85
Member
 
Registered: Mar 2009
Posts: 47

Original Poster
Rep: Reputation: 15
I don't know. I'm getting kind of frustrated because I've been at this all day now, and I just can't figure it out. I guess all I wanted to do was see what the second commonly used shell is that users use to login too. But I'm not exactly sure. lol I figured the grep command that I used would tell me but apparently not.

I did try:

Code:
$ grep -vc /bin/bash /etc/passwd
38
and got 38, but that doesn't tell me what shell. I'm about to pull my hair, does anyone ever do that when they are unable to figure something out in linux? LOL
 
Old 03-14-2009, 11:09 PM   #6
nilleso
Member
 
Registered: Nov 2004
Location: ON, CANADA
Distribution: ubuntu, RHAS, and other unmentionables
Posts: 372

Rep: Reputation: 31
The following command will list the shells. The first column is the count.
When you don't know how to do something.. try harder.

cheers

Code:
awk -F":" '{print $7}' /etc/passwd|sort|uniq -c|sort -rn
Code:
812 /bin/bash
446 /bin/ksh
217 /bin/sh
 16 /bin/false
  1 /usr/sbin/nologin
  1 /bin/sync
 
Old 03-14-2009, 11:22 PM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,169

Rep: Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943
And note the use of several commands to achieve a result. In general this is an attribute if *nix systems - use small programs to build the answer.
 
Old 03-15-2009, 02:34 AM   #8
shorte85
Member
 
Registered: Mar 2009
Posts: 47

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by nilleso View Post
The following command will list the shells. The first column is the count.
When you don't know how to do something.. try harder.

cheers

Code:
awk -F":" '{print $7}' /etc/passwd|sort|uniq -c|sort -rn
Code:
812 /bin/bash
446 /bin/ksh
217 /bin/sh
 16 /bin/false
  1 /usr/sbin/nologin
  1 /bin/sync
This ended up working, and I also used:

Code:
$ cat /etc/shells
which listed off the shells that we were able to use, which was very helpful. I then went on to checking each one with the

Code:
$ grep -c "/bin/bash" /etc/passwd
which gave me the numbers, then I just changed the "/bin/bash" to the other shell names and got the answer. The shell that is the second commonly used shell is /sbin/nologin which was 34.

Thanks again, I appreciate you helping me with this one. I believe I got what I was looking for. HE HE!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Really strange problem - RedHat /bin/sh vs /bin/bash leeharris Programming 4 02-13-2009 06:35 AM
Difference between /bin/bash & /bin/sh paragkalra Programming 11 01-02-2009 06:10 AM
How to add paths to sbin, bin/bash, bin sh for users gopi.d Fedora 3 12-07-2007 12:47 AM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM
bin/bash:usr/bin/lpr NO SUCH FILE OR DIRECTORY Adibe_Hamm Linux - Newbie 3 10-14-2003 02:30 AM


All times are GMT -5. The time now is 09:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration