-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_mentees.sh
40 lines (29 loc) · 1.33 KB
/
create_mentees.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
# Path to the input file
input_file="/home/menteeDetails.txt"
# Base directory for mentees
base_dir="/home/users/core/mentees"
# Read the input file line by line, skipping the first line
sudo tail -n +2 "$input_file" | while IFS=' ' read -r name rollno; do
# Create the user account without creating a home directory
sudo useradd -M -s /bin/bash "$name"
# Create the user's home diretory in the mentees directory
user_home="$base_dir/$name"
sudo mkdir -p "$user_home"
sudo chown "$name:$name" "$user_home"
# Set the user's home directory
sudo usermod -d "$user_home" "$name"
# Create the required text files in the user's home directory
sudo touch "$user_home/domain_pref.txt"
sudo touch "$user_home/task_completed.txt"
sudo touch "$user_home/task_submitted.txt"
sudo chown "$name:$name" "$user_home/domain_pref.txt"
sudo chown "$name:$name" "$user_home/task_completed.txt"
sudo chown "$name:$name" "$user_home/task_submitted.txt"
# Add users to group mentees
sudo usermod -aG mentees "$name"
echo "alias submitTask='bash /home/submit_task.sh'" >> /home/users/core/mentees/$name/.bashrc
source /home/users/core/mentees/$name/.bashrc
echo "User '$name' created with '$rollno' with home directory '$user_home'."
done
echo "All mentees have been processed."