-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsc_user_addgroup_sudo.sh
39 lines (34 loc) · 1.44 KB
/
sc_user_addgroup_sudo.sh
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
###################################################################
#Script Name :addgroup
#Description :Add the User to the sudo Group: RedHat: wheel Debian: sudo
#Notes :file: userlist.txt"
#Author :krimsoda
###################################################################
# Check if the userlist file exists
if [ ! -f "userlist.txt" ]; then
echo "Userlist file 'userlist.txt' not found in the current directory."
exit 1
fi
# Check if the sudo group exists
if grep -q '^sudo:' /etc/group; then
sudo_group="sudo"
else
sudo_group="wheel"
fi
# Read the userlist file line by line and add users to the appropriate group
while IFS= read -r username; do
# Check if the username is empty or starts with a comment symbol "#"
if [[ -z "$username" || "$username" =~ ^# ]]; then
continue
fi
# Check if the user exists
if id "$username" &>/dev/null; then
# Add the user to the appropriate group
usermod -aG "$sudo_group" "$username"
echo "User '$username' added to the '$sudo_group' group."
else
echo "User '$username' not found. Skipping adding to the '$sudo_group' group..."
fi
done < "userlist.txt"
echo "Adding users to the '$sudo_group' group completed."