#!/bin/bash
count=$(cat /etc/sudoers | grep "ALL" | grep -v ^# | wc -l)
echo "The following users have sudo access to root"
for i in $(seq 1 $count)
do
line=$(cat /etc/sudoers | grep "ALL" | grep -v ^# | head -n $i | tail -n 1 | tr "=()" " ")
cnt=$(echo $line | sed -e 's/[^ALL]/ /g' | wc -w)
if [ $cnt -eq 3 ]; then
myuser=$(echo $line | awk -F' ' '{print $1}')
mygroup=$(echo $myuser | grep ^%)
if [ -z "$mygroup" ]; then
User="$myuser"
NAME=`grep $User /etc/passwd | awk -F":" '{print $5}'`
echo "$myuser"
else
Group="$(echo $mygroup | tr "%" " ")"
GID=(`grep $Group /etc/group | awk -F ":" '{print $3}'`)
#NAME=`grep $GID /etc/passwd | awk -F":" '{print $1 " "$5}'`
echo "$myuser"
fi
fi
done
count=$(cat /etc/sudoers | grep "ALL" | grep -v ^# | wc -l)
echo "The following users have sudo access to root"
for i in $(seq 1 $count)
do
line=$(cat /etc/sudoers | grep "ALL" | grep -v ^# | head -n $i | tail -n 1 | tr "=()" " ")
cnt=$(echo $line | sed -e 's/[^ALL]/ /g' | wc -w)
if [ $cnt -eq 3 ]; then
myuser=$(echo $line | awk -F' ' '{print $1}')
mygroup=$(echo $myuser | grep ^%)
if [ -z "$mygroup" ]; then
User="$myuser"
NAME=`grep $User /etc/passwd | awk -F":" '{print $5}'`
echo "$myuser"
else
Group="$(echo $mygroup | tr "%" " ")"
GID=(`grep $Group /etc/group | awk -F ":" '{print $3}'`)
#NAME=`grep $GID /etc/passwd | awk -F":" '{print $1 " "$5}'`
echo "$myuser"
fi
fi
done