Compare commits

..

4 Commits

Author SHA1 Message Date
Clemens Schwaighofer
4629b58a7e Skip empty group on login check 2024-11-11 17:06:24 +09:00
Clemens Schwaighofer
d8cd628ddd Fix for check last login script
the data reading was split with " " (space) which in the while read kept
it as one row, changed the split character to "\n"
2024-10-24 13:57:04 +09:00
Clemens Schwaighofer
76f9056069 Fix user create with groups
Move the params into array that we add as dynamic parameters to call
2024-10-11 14:39:56 +09:00
Clemens Schwaighofer
74e7e9823f Bug fix for user create group part 2024-10-11 09:25:41 +09:00
2 changed files with 15 additions and 5 deletions

View File

@@ -111,6 +111,10 @@ for ssh_group in "${ssh_groups[@]}"; do
fi;
fi;
while read -r username; do
# skip empty, if group exists but has no users
if [ "${username}" = "" ]; then
continue;
fi;
# check that user exists in passwd
if ! id "${username}" &>/dev/null; then
out_string="[!] User $username does not exists in /etc/passwd file";
@@ -294,7 +298,7 @@ for ssh_group in "${ssh_groups[@]}"; do
printf "${CSV_LINE}" "${account_id}" "${region}" "${instance_id}" "$(hostname)" "${username}" "${main_group}" "${ssh_group}" "${user_create_date_out}" "${account_age}" "${last_login_date}" "${last_login}" "${never_logged_in}" "${login_source}" "${out_string}"
;;
esac;
done <<< "$(grep "${ssh_group}:" /etc/group | cut -d ":" -f 4 | sed -e 's/,/ /g')";
done <<< "$(grep "${ssh_group}:" /etc/group | cut -d ":" -f 4 | sed -e 's/,/\n/g')";
done;
if [ "${OUTPUT_TARGET}" = "text" ]; then
if [ -n "${lock_accounts}" ]; then

View File

@@ -234,11 +234,11 @@ while read -r i; do
fi;
ssh_group="ssh${ssh_access_type}";
# sshallow group is always added
sub_group_opt=" -G ${ssh_group}";
sub_group_opt=("${ssh_group}");
# check if "," inside and extract sub groups
if [ -z "${_group##*,*}" ]; then
sub_group=$(echo "${_group}" | cut -d "," -f 2-);
sub_group_opt=" -G ${ssh_group},${sub_group}";
sub_group_opt+=("${sub_group}");
fi;
# POS 5: do we have a password preset
_password=$(echo "${i}" | cut -d ";" -f 5);
@@ -314,11 +314,17 @@ while read -r i; do
echo "-- Skip '${username}:${group}(${sub_group})'";
else
echo "++ Create '${username}:${group}(${sub_group})'";
params=(
"-c" "$(date +"%F")" "-s" "${user_login_shell}"
"-g" "${group}" "-G" "$(IFS=, ; echo "${sub_group_opt[*]}")"
"-d" "${HOME_FOLDER}${username}" "-m"
"${username}"
);
if [ ${TEST} -eq 0 ]; then
# comment is user create time
useradd -c "$(date +"%F")" -s "${user_login_shell}" -g "${group}${sub_group_opt}" -d "${HOME_FOLDER}${username}" -m "${username}";
useradd "${params[@]}";
else
echo "$> useradd -c \"$(date +"%F")\" -s \"${user_login_shell}\" -g \"${group}${sub_group_opt}\" -d \"${HOME_FOLDER}${username}\" -m \"${username}\"";
echo "$> useradd ${params[*]}";
fi;
fi;
# set the auth file