0

We have multiple servers and i would like to print users list and access level using bash.

I tried below command but could not get exact result what i wanted to:

awk '/Allow root/{p=5} p > 0 {print $1; p--}'   /etc/sudoers

above command just give me five entries as below

## 
root    
abcd
ghfd
fcff

but I should get the O/P as below:

UserList      AccessLevel
root           ALL
abcd        !/usr/bin/*

Can i get the output as above?

0

After doing so much experiments i am able to achieve it as close as possible by below command.

grep "ALL=(ALL)" /etc/sudoers | awk  '{ print $1 "\t""\t""\t" $3 $4}' | cut -d '#' -f1 | cut -d '%' -f1

and the output is as below:

xxxx                    ALL
xxxxxx                      ALL
xxxx                 ALL


xxxx                        NOPASSWD:ALL
abcd                 ALL
xxxx                 ALL

But still i am getting space separated output. i want to skip that spaces in output.

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.