Good morning all. I have been working on this for over a week and this is what I have. Please be gentle and explain to me what I have done wrong or right. Also if there is any way to make this code shorter THANK YOU. MY instructions and code follows.
Instructions
project will consist of multiple menu items that have sub menus for multiple functions. They are as follows:
Option 1 File functions
Subfunction Open file and enter five comic names –close file
Subfuntion2 Open file and read names from file above
Subfunction3 – Prompt user for file name and search for that file-display results
Subfunction4 – Prompt user for folder to search for and display results
Option 2 Network functions
Subfunction 1Prompt user for IP address and ping that address
Subfunction2 Display all used ip addresses on your network
Option 3 Math functions
Subfunction 1 prompt user for two numbers and add them together display result
Subfunction 2 prompt user for two numbers and multiply them together display result
Option 4 Display Options
Subfunction 1- Display the following (you must use loops – no separate print line functions)
*
**
***
****
*****
****
***
**
*
Option 5 Adminusers
Subfunction1 – display users
Subfunction 2- add user
Subfunction3- delete user
Subfunction4- change user password
(in all of the user functions you will prompt admin user for name to add, delete, etc)
Option 6 Date
Subfunction1 show current date
Subfunction2 show calendar for current month
Subfunction3 test to show if today is Friday the 13th or not
Option 7- email functions
Subfunction 1-test to see if smtp server is installed
Subfunction 2- send test email to current user
My code
Code:
#!/bin/bash
trap '' 2
while true
do
clear
echo "=========="
echo "Menu"
echo "=========="
echo "Enter 1 File functions: "
echo "Enter 2 Network functions: "
echo "Enter 3 Math functions: "
echo "Enter 4 Display Options: "
echo "Enter 5 Adminusers: "
echo "Enter 6 Date: "
echo "Enter 7 Email functions: "
echo "Enter 8 to exit menu: "
echo "Enter your selection "
read answer
case "$answer" in
1)
File Funtions ()
{
clear
echo "=========="
echo "File Functions"
echo "a) open file and enter five comic names"
echo "b) Open file and read names from file above"
echo "c) Enter File name to search"
echo "d) Enter folder to search"
echo "e) Quit to Main Menu"
echo "=========="
while :
do
read answer
case $answer in
"a")
open blank.txt ;;
"b")
open blank.txt and read ;;
"c")
find ./ -type f -name \$1 ;;
"d")
find . -type d ;;
"e")
Quit to Main Menu ;;
esac
done
}
File Functions;
;;
Network Functions ()
{
clear
echo "=========="
echo "Network Functions"
echo "a) Enter ip address to Ping"
echo "b) Display all used ip addresses on network"
echo "=========="
while :
do
read answer
case $answer in
"a")
ping ;;
"b")
$ /sbin/ifconfig ;;
esac
done
}
Network Functions;
;;
Math Functions ()
{
clear
echo "=========="
echo "Math Functions"
echo "a) Enter 2 numbers to add together"
echo "b) Enter 2 numbers to multiply together"
echo "=========="
while :
do
read answer
case $answer in
"a")
echo -n "Number1: "
read num1
echo -n "Number2: "
read num2
echo "$num1 + $num2 = 'expr $num1 + $num2'" ;;
"b")
echo -n "Number1: "
read num1
echo -n "Number2: "
read num2
echo "$num1 * $num2 = 'echo "$num1*$num2"|bc'" ;;
esac
done
}
Math Functions;
;;
Display Options ()
{
clear
echo "=========="
echo "Display Options"
echo "a) option"
echo "=========="
while :
do
read $answer
case $answer in
"a")
for (( c=*; c<=*****; c>=*; c++ ))
do
echo "$c" ;;
done
}
Display Options;
;;
Adminusers ()
{
clear
echo "=========="
echo "Adminusers"
echo "Enter 1 to add user 1: "
echo "Enter 2 to delete user 2: "
echo "Enter 3 to change user password 3: "
echo "Enter q to exit the menu q: "
echo "Enter your selection \c"
read answer
case "$answer" in
1) useradd ;;
2) userdel ;;
3) passwd ;;
q) exit ;;
esac
done
}
Adminusers;
;;
Date ()
{
clear
echo "=========="
echo "Date"
echo "a) Current Date"
echo "b) Show Calender"
echo "c) Friday the 13th"
echo "=========="
while :
do
read answer
case $answer in
"a")
do
date
echo $words
;;
"b")
do
cal
echo $words
;;
"c")
DAY=$(date +%a)
if [ $DAY == "Fri" ]
then
echo "Today is Friday"
fi
esac
done
}
Date;
;;
Email Functions ()
{
clear
echo "=========="
echo "Email Functions"
echo "a) Test if local SMTP server is running"
echo "b) Send test email"
echo "=========="
while :
do
read answer
case $answer in
"a")
do
# echo -e "quit" | nc localhost 25
220 ubuntu ESMTP Postfix (Ubuntu)
221 2.0.0 Bye
;;
"b")
do
du -sh | mail -s "test" user@yourmaildomain.com
;;
esac
done
}
Email Functions;
;;
Quit ()
{
esac
done
}
Quit;
;;
3) passwd ;;
4) exit ;;
esac
done
End of code Thank you for shareing your knowledge with me.