Repository navigation
Expand file tree
/
Copy pathuserinfo.sh
More file actions
39 lines (34 loc) · 1.44 KB
/
Copy pathuserinfo.sh
File metadata and controls
39 lines (34 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# +-------------------------------------------------------------+
# | this script takes a username or UID as argument and prints |
# | all available information about the user to the terminal |
# | |
# | USAGE: |
# | ./userinfo <username or UID> |
# +-------------------------------------------------------------+
exec 2>/dev/null # because fuck errors
UNAMES=$(cat /etc/passwd | cut -d ':' -f1)
UIDS=$(cat /etc/passwd | cut -d ':' -f3)
UNAME_FOUND=$( echo "$UNAMES" | grep -cim1 -Fx $1)
UID_FOUND=$( echo "$UIDS" | grep -cim1 -Fx $1)
if [ $UNAME_FOUND == 1 ]; then
echo -e "\tfound user, printing details"
ID=$(getent passwd $1 | cut -d ':' -f3)
elif [ $UID_FOUND == 1 ]; then
echo -e "\tfound user-id, printing details"
ID=$1
else
echo -e "\tuser(id) not found - quitting"
exit -1
fi
USERINFO=$(awk -F":" 'int($3)=='"$ID"'' /etc/passwd)
echo -e "\tUSERNAME:\t$(echo $USERINFO | cut -d ':' -f1)"
echo -e "\tPW SET:\t\t$(if [[ $(echo $USERINFO | cut -d ':' -f2) == x ]]; then echo yes; else echo no; fi)"
echo -e "\tUSER-ID:\t$(echo $USERINFO | cut -d ':' -f3)"
echo -e "\tGROUP-ID:\t$(echo $USERINFO | cut -d ':' -f4)"
echo -e "\tUSER ID INFO:\t$(echo $USERINFO | cut -d ':' -f5)"
HOMEDIR=$(echo $USERINFO | cut -d ':' -f6)
echo -e "\tHOME DIR:\t$HOMEDIR"
echo -e "\tHOMEDIR FILES:\t$(find $HOMEDIR -type f | wc -l)"
echo -e "\tHOMEDIR SIZE:\t$(du -sh $HOMEDIR | cut -d$'\t' -f1)"
echo -e "\tSHELL:\t\t$(echo $USERINFO | cut -d ':' -f7)"