-
Notifications
You must be signed in to change notification settings - Fork 0
/
task1.sh
92 lines (63 loc) · 2.47 KB
/
task1.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# Function for permissions
permissions() {
local user=$1
local file=$2
sudo chown "$user:$user" "$file"
sudo chmod 600 "$file"
}
# Create user doctors
for i in {1..3}; do
username="doctor$i"
home_dir="/home/$username"
sudo useradd -m -d "$home_dir" -s /bin/bash "$username"
echo "Slot: Wing:" | sudo tee "$home_dir/Available.txt"
echo "Slot: Wing: Patient: " | sudo tee "$home_dir/Appointment.txt"
permissions "$username" "$home_dir/Available.txt"
permissions "$username" "$home_dir/Appointment.txt"
done
# Create user patients
for i in {1..3}; do
username="patient$i"
home_dir="/home/$username"
sudo useradd -m -d "$home_dir" -s /bin/bash "$username"
echo "Slots: " | sudo tee "$home_dir/PatientDetails.txt"
echo "Symptoms: " | sudo tee "$home_dir/Prescription.txt"
permissions "$username" "$home_dir/PatientDetails.txt"
permissions "$username" "$home_dir/Prescription.txt"
done
# Create usr wing admins
wing_admins=("wingadmin1" "wingadmin2" "wingadmin3")
for admin in "${wing_admins[@]}"; do
home_dir="/home/$admin"
sudo useradd -m -d "$home_dir" -s /bin/bash "$admin"
sudo mkdir "$home_dir/Patient"
sudo mkdir "$home_dir/Doctor"
echo "InPatient.txt" | sudo tee "$home_dir/Patient/InPatient.txt"
echo "InDoctor.txt" | sudo tee "$home_dir/Doctor/InDoctor.txt"
permissions "$admin" "$home_dir/Patient/InPatient.txt"
permissions "$admin" "$home_dir/Doctor/InDoctor.txt"
done
# Appointment function
echo
sudo echo "Appointment functionality:"
read -p "Enter doctor's username: " doctor_username
read -p "Enter patient's username: " patient_username
read -p "Enter chosen timing: " chosen_timing
# Update doctor's shift
doctor_home="/home/$doctor_username"
echo "Slots: $chosen_timing" | sudo tee "$doctor_home/Available.txt"
# Update inDoctor.txt
wing_name="${doctor_home##*/}"
admin_home="/home/wingadmin$wing_name"
echo "Doctor: $doctor_username, Timings: $chosen_timing" | sudo tee "$admin_home/InDoctor.txt"
# Check for time
if grep -q "$chosen_timing" "$doctor_home/Available.txt"; then
# Update patient's appointment
patient_home="/home/$patient_username"
echo "Appointment with $doctor_username, Timing: $chosen_timing" | sudo tee "$patient_home/Appointment.txt"
# Update inPatient.txt
echo "Patient: $patient_username, Doctor: $doctor_username, Timing: $chosen_timing" | sudo tee "$admin_home/Patient/InPatient.txt"
else
sudo echo "Chosen timing is not available. Please choose another timing."
fi