Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

a regular expression

Posted on 2011-03-23
5
Medium Priority
?
444 Views
Last Modified: 2012-05-11
I want a scipt to display a list of all the users on your system who log in the Bash shell as a default.(Linux Fedora 14)
I guess grep is helpful  but not sure.

Thanks.
0
Comment
Question by:zhshqzyc
  • 2
  • 2
5 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 100 total points
ID: 35199946

awk -F: '{if($NF~"bash") print $1, $NF}' /etc/passwd

wmp
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35199968
.. or just

grep "bash" /etc/passwd  | cut -f1,7 -d:
0
 
LVL 4

Expert Comment

by:roemelboemel
ID: 35200051
I would do it with awk as with a simple grep you would als catch a user called "bash" or when you have email addresss in the gecos field and your company has the domain "i-love-bash.org" as email domain...
awk -F: ' $7~/\/bash$/{ print $1":"$7 } ' 

Open in new window

0
 
LVL 4

Assisted Solution

by:roemelboemel
roemelboemel earned 100 total points
ID: 35200077
missed the passwd file
awk -F: ' $7~/\/bash$/{ print $1":"$7 } '  /etc/passwd

Open in new window

0
 

Author Comment

by:zhshqzyc
ID: 35200307
awk -F: ' $7~/\/bash$/{ print $1":"$7 } '

Open in new window

It is not working but thanks for your input.

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question