Skip to content
Snippets Groups Projects
Commit 312763d0 authored by vincent.andrey1's avatar vincent.andrey1
Browse files
parents f61b09fd 2bca2630
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
# Usage:
# get-groups.sh username
#
# username is the name of the user you want to know the groups of
# cat /etc/group | grep $USER | cut -d ":" -f 1
#Define user input
USERNAME=$1
function exist {
if [ $(grep -c ${USERNAME} /etc/passwd ) -eq 0 ];then
echo "Cet utilisateur n'existe pas" >&2
exit 0
fi
}
function mainGroup {
local pass=$(cat /etc/passwd | grep ${USERNAME} | cut -d ":" -f 4)
echo $(cat /etc/group | grep ${pass} | cut -d ":" -f 1)
}
function groups {
echo $(cat /etc/group | grep ${USERNAME} | cut -d ":" -f 1 | sed "/${USERNAME}/d")
}
# Test for mandatory inputs
if [ -z "${USERNAME}" ];then
echo "Usage:" >&2
echo -e "\t$0 username" >&2
exit 0
fi
if [ !$(exist) ];then
echo $(mainGroup) $(groups)
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment