Этот сценарий работает нормально, но создает только имя. Я все еще учусь писать сценарии для Linux, так что, возможно, это неправильно. Это сочетание того, что я знаю, онлайн-исследований и, да, некоторого вклада ИИ (пожалуйста, не судите меня). Я не могу хоть убей понять, почему там указано только имя. Будем очень признательны за любые предложения.
Код: Выделить всё
#!/bin/bash
# Source the secure configuration file
source /etc/secure_config/db_config.conf
# Function to generate a random password
generate_password() {
tr -dc 'A-Za-z0-9' "$output_file"
while read -r full_name; do
# Skip empty lines
[[ -z "$full_name" ]] && continue
# Extract first letter of the first name and full last name
first_letter=$(echo "$full_name" | awk '{print tolower(substr($1, 1, 1))}')
last_name=$(echo "$full_name" | awk '{print tolower($NF)}')
# Generate a username
username="${first_letter}${last_name}"
# Check for duplicates and append numbers to make them unique
counter=0 # Reset counter for each name
while id "$username" &>/dev/null; do
counter=$((counter + 1))
username="${first_letter}${last_name}${counter}"
done
# Generate a random password
password=$(generate_password)
# Create the user and database
create_user_and_db "$full_name" "$username" "$password"
# Write user details to the output file
echo -e "\n\"$full_name\"\nLogin: \"$username\"\nPassword: \"$password\"\n\nYour login and password are case sensitive.\n\nYou may login remotely to access the CS lab webserver and Unix environment:\nScience Department:\n\tDragon.csustan.edu - Linux Debian" >> "$output_file"
done < "$input_file"
echo "User creation completed successfully. User details are stored in '$output_file'."
sudo ./createDatabaseUsers.sh
Создание пользователя успешно завершено. Данные пользователя хранятся в файле /usr/local/bin/addstudentsMysql/usersCreated.txt.
Подробнее здесь: https://stackoverflow.com/questions/791 ... pt-only-cr