I am trying to implement a login screen to the following code how would i go about doing so. I have try to place the password in a variable using if statements which would usually work but as i have the system in a while loop i think i need to find another method.
#!/bin/bash
#Filename: Assigntest Author: Luke Francis
quit=n
while [ "$quit" = "n" ]
do
clear
echo "OPERATOR ADMINISTRATIVE TOOL"
echo
echo "1. User Information"
echo "2. Network Connectivity"
echo "3. Processes"
echo "4. System Information"
echo "5. Hardware Utilization"
echo "Q. Quit"
echo
echo "Which option do you require?"
read menunumber
case $menunumber in
1)clear
echo "USER INFORMATION"
echo
echo "1. Registered Users"
echo "2. Disk Usage"
echo "3. Last Logins"
echo "4. Users Currently Logged In"
echo "5. Total number of users"
echo "B. Back to Main Menu"
echo "Q. Quit"
echo
echo "Which option do you require?"
read menunumber2
case $menunumber2 in
1)clear
echo "The users registered on the system are:"
echo
awk -F: '{print $1}' /etc/passwd
echo
echo "Hit the Enter Key to continue"
read junk;;
2)clear
echo "Disk Usage is as follows:"
echo
du
echo
echo "Hit Enter Key to continue"
read junk;;
3)clear
echo "Information on last noted login can be found next to each username."
echo
last
echo
echo "Hit Enter Key to continue"
read junk;;
4)clear
echo "Users currently logged in are:"
echo
w
echo
echo "Hit Enter Key to continue"
read junk;;
5)clear
echo "The total number of users are:"
echo
who -q
echo
echo "Hit Enter Key to continue"
read junk;;
Q|q)clear
echo "Are you sure you want to quit? Y/N"
read choice1
case $choice1 in
N|n)clear
echo "Hit Enter Key to continue"
read junk;;
Y|y)quit=y;;
*)clear
sleep 1;;
esac
;;
esac
;;
2)clear
echo "NETWORK CONNECTIVITY"
echo
echo "1. NIC Status"
echo "2. Machine Availability"
echo "B. Back to Main Menu"
echo "Q. Quit"
echo
echo "Which option do you require?"
read menunumber4
case $menunumber4 in
1)clear
echo "Information reagrding NIC status can be found below:"
echo
/sbin/ifconfig
echo
echo "Hit the Enter Key to continue"
read junk;;
2)clear
echo "Available hosts and addresses are shown below:"
echo
cat /etc/hosts
echo
echo "Hit Enter Key to continue"
read junk;;
Q|q)clear
echo "Are you sure you want to quit? Y/N"
read choice2
case $choice2 in
N|n)clear
echo "Hit Enter key to continue"
read junk;;
Y|y)quit=y;;
*)clear
sleep 2;;
esac
;;
esac
;;
3)clear
echo "PROCESSES"
echo
echo "1. Running Processes"
echo "2. Installed Software"
echo "B. Back to Main Menu"
echo "Q. Quit"
echo
echo "Which option do you require?"
read menunumber5
case $menunumber5 in
1)clear
echo "Current running processes are displayed below"
echo
ps aux
echo
echo "Hit Enter key to continue"
read junk;;
2)clear
echo "The software currently installed on this host is:"
echo
rpm -qa
echo
echo "Hit Enter key to continue"
read junk;;
Q|q)clear
echo "Are you sure you want to quit? Y/N"
read choice3
case $choice3 in
N|n)clear
echo "Hit Enter key to continue"
read junk;;
Y|y)quit=y;;
*)clear
sleep 3;;
esac
;;
esac
;;
4)clear
echo "SYSTEM INFORMATION"
echo
echo "1. Machine Name"
echo "2. System Date & Time"
echo "3. Licensing Information"
echo "4. Last System Reboot"
echo "B. Back to Main Menu"
echo "Q. Quit"
echo
echo "Which option do you require?"
read menunumber6
case $menunumber6 in
1)clear
echo "The name of the machine is:"
uname -m
echo
echo "Hit Enter key to continue"
read junk;;
2)clear
echo "The current date and time is:"
echo
date
echo
echo "Hit Enter key to continue"
read junk;;
4)clear
echo "The last scheduled system reboot was:"
echo
who -b
echo
echo "Hit Enter Key to continue"
read junk;;
B)read junk;;
Q|q)clear
echo "Are you sure you want to quit? Y/N"
read choice4
case $choice4 in
N|n)clear
echo "Hit Enter key to continue"
read junk;;
Y|y)quit=y;;
*)clear
sleep 4;;
esac
;;
esac
;;
5)clear
echo "HARDWARE UTILISATION"
echo
echo "1. Unix Filesystem Usage"
echo "2. RAM Availability"
echo "3. Swap Space"
echo "4. CPU Utility"
echo "Q. Quit"
echo
echo "Which option do you require?"
read menunumber6
case $menunumber6 in
1)clear
echo "Information regarding usage of the Unix filesystem as requested can be found below:"
echo
df -h
echo
echo "Hit Enter Key to continue"
read junk;;
2)clear
echo "RAM usage information can be found below:"
echo
cat /proc/meminfo
echo
echo "Hit Enter Key to continue"
read junk;;
3)clear
echo "The amount of free and used Swap space is:"
echo
cat /proc/meminfo
echo
echo "Hit Enter Key to continue"
read junk;;
4)clear
echo "The first column indicates size of CPU run queue"
echo
vmstat
echo
echo "Hit Enter Key to continue"
read junk;;
esac
;;
Q|q)clear
echo "Are you sure you want to quit? Y/N"
read choice5
case $choice5 in
N|n)clear
echo "Hit Enter key to continue"
read junk;;
Y|y)quit=y;;
*)clear
sleep 5;;
esac
;;
esac
done
clear
echo "Thank you for using the Operator Administrative Tool"
I would like the login screen to appear first, and if the password 12345 was not enetered then a message saying incorrect password would be displayed. I have tried to implement this but am not having much luck. How would this be implemented to the code above? All help is appreciated. Thanks