0

I'm trying to achieve the following: List my Linux users, that have set bin/bash in /etc/passwd AND append each user's info from id [username] into the print statement, something in the lines of:

cat /etc/passwd | grep bin/bash | awk -F\: '{print $1";"$(id $1)}'

(which obviously does not work ;) )

I've got the feeling that I'm pretty close; what am I missing?

Output is supposed to be (see DavDav's comment):

User1;uid=1000(User1) gid=1000(User1) groups=1000(User1) 
User2;uid=1001(User2) gid=1001(User2) groups=1001(User2) 
User3;uid=1002(User3) gid=1002(User3) groups=1002(User3) 
2
  • What is the expected output? Oct 4, 2018 at 13:05
  • Output is supposed to be; User1;uid=1000(User1) gid=1000(User1) groups=1000(User1) User2;uid=1001(User2) gid=1001(User2) groups=1001(User2) User3;uid=1002(User3) gid=1002(User3) groups=1002(User3)
    – DavDav
    Oct 4, 2018 at 13:18

3 Answers 3

3

How about

 </etc/passwd grep bin/bash | cut -d: -f1 | xargs -n1 id
2
  • Hoppla - original question modified.
    – RudiC
    Oct 4, 2018 at 13:38
  • 1
    use xargs -I{} sh -c "echo -n {}\;; id {};"
    – pLumo
    Oct 4, 2018 at 13:43
1

Try this,

 awk -F ':' '/bin\/bash/ {printf ($1";"); system("id "$1)}' /etc/passwd
  • system will executes the command and returns the value to awk
0

Here's another option:

for i in $(grep /bin/bash /etc/passwd | awk -F: '{ print $1 }'); do
    echo "${i};$(id ${i})"
done

The grep ... awk ... will generate the list of user names corresponding to lines in /etc/passwd that contain /bin/bash. On each iteration of the for loop, i will be one of those usernames. The echo then prints the username followed by a semi-colon, followed by the output of id for that username.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .