user-management/user_management.sh

31 lines
1.1 KiB
Bash
Raw Permalink Normal View History

2023-07-14 08:08:33 +00:00
#!/bin/bash
# Step 1: Set Configuration using Environment Variables
source config.cfg
# Step 2: Retrieve User Data from a CSV File
while IFS=',' read -r username password email
do
# Step 3: Process User Data
# Create a new user
sudo dscl . -create "/Users/$username"
sudo dscl . -create "/Users/$username" UserShell "/bin/bash"
sudo dscl . -create "/Users/$username" RealName "$username"
sudo dscl . -create "/Users/$username" UniqueID "<userID>"
sudo dscl . -create "/Users/$username" PrimaryGroupID "<groupID>"
sudo dscl . -create "/Users/$username" NFSHomeDirectory "/Users/$username"
sudo dscl . -passwd "/Users/$username" "$password"
sudo dscl . -append /Groups/admin GroupMembership "$username"
# Step 4: Provide Additional Details to the User
echo "Welcome, $username! Here are some additional details." > "/Users/$username/details.txt"
# Include more information as needed
# Step 5: Create Output File
echo "User $username has been created successfully." >> output.txt
done < userdata.csv
# Step 6: Add Cronjob
echo "0 8 * * 0 /path/to/script.sh" | crontab -