#!/bin/bash
LOG_FILE=/var/log/user_management.log PASSWORD_FILE=/var/secure/user_passwords.txt
if [ $# -ne 1 ]; then echo "Usage: $0 <input_file>" exit 1 fi
INPUT_FILE=$1
touch $LOG_FILE chmod 600 $LOG_FILE touch $PASSWORD_FILE chmod 600 $PASSWORD_FILE
while IFS=';' read -r user groups; do
user=$(echo "$user" | tr -d '[:space:]') groups=$(echo "$groups" | tr -d '[:space:]')
groupadd $user
useradd -m -g $user -s /bin/bash $user
IFS=',' read -r -a group_array <<< "$groups" for group in "${group_array[@]}"; do groupadd $group usermod -aG $group $user done
password=$(pwgen -s 12 1)
echo "$user:$password" | chpasswd
echo "Created user $user with password
echo "$user,$password" >> $PASSWORD_FILE done < $INPUT_FILE