-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenStudent.sh
executable file
·54 lines (49 loc) · 1.68 KB
/
genStudent.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
#Alias genStudent in .bashrc runs this file
# Create HAD user and home directory
useradd HAD
mkdir /home/HAD
chown HAD /home/HAD
cp /home/arjun/Documents/delta-sysad/mess.txt /home/HAD/mess.txt
echo -e "[x] Created HAD user and home directory\n"
# Student details file input
# filePath="/home/arjun/Documents/delta-sysad/studentDetails.txt"
read -p 'Enter file path: ' filePath
# Create Hostel home directories
echo -e "\nCreating Hostels home directories............"
while read line
do
read -a studentData <<< "$line"
hostel=${studentData[2]}
if [ -d "/home/$hostel" ];
then
echo "$hostel already present"
else
useradd $hostel
mkdir /home/$hostel
chown $hostel /home/$hostel
touch /home/$hostel/announcements.txt
touch /home/$hostel/feeDefaulters.txt
echo "[x] Created $hostel user and home directory"
fi
done < $filePath
#Creating students home directories
echo -e "\nCreating student home directories............"
depts=("CSE" "ECE" "EEE" "ME" "ICE" "PRD" "MME" "CL" "CHE")
while read line
do
#Extracting all data
read -a studentData <<< "$line"
name=${studentData[0]}
rollno=${studentData[1]}
hostel=${studentData[2]}
roomno=${studentData[3]}
mess=${studentData[4]}
dept=${depts[$((RANDOM % 9))]}
useradd $name
mkdir /home/$hostel/$roomno
mkdir /home/$hostel/$roomno/$name
echo -e "Name $name\nRollNo $rollno\nDept $dept\nYear 1\nHostel $hostel" > /home/$hostel/$roomno/$name/userDetails.txt
echo -e "TuitionFee 0\nHostelRent 0\nServiceCharge 0\nMessFee 0" > /home/$hostel/$roomno/$name/fees.txt
echo "[x] Created $name user and home directory"
done < $filePath