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) 
  • What is the expected output? – Nasir Riley Oct 4 '18 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 '18 at 13:18
2

How about

 </etc/passwd grep bin/bash | cut -d: -f1 | xargs -n1 id
  • Hoppla - original question modified. – RudiC Oct 4 '18 at 13:38
  • 1
    use xargs -I{} sh -c "echo -n {}\;; id {};" – pLumo Oct 4 '18 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.