Instructions PRGRAMMING IN UNIX This project incorporates many skills learned th
ID: 665265 • Letter: I
Question
Instructions PRGRAMMING IN UNIX
This project incorporates many skills learned throughout this course. Prepare the shell program described below using a modular approach that uses functions where appropriate.
First, identify the password file attached to this project, the one used in assignment 5, or create your own as desired. It will be used in this project. Make sure it at least has your own “logname” username of yourself in the file.
Second, create an office telephone directory file containing three columns of the last name, first name, and phone number of at least 10 individuals. Then create a shell program that accepts either one (last name) or two (last name and first name) arguments. Check to ensure that one or two arguments are on the command line. If there is only one argument, display a message informing the user that more than one entry might be returned from the phone book. Exit the program if there are less than one or more than two arguments.
Third, after checking on the arguments, display a prompt asking what phone book directory file to search. Test to ensure that the entry is a valid regular file that is not zero bytes in length. If not a regular file, exit the program with an appropriate message to the user on the screen. Then check to see that there are three columns in the file. If there are not three columns, display a message indicating that the file does not contain a configuration consistent with a phone book and exit the program with an appropriate message displayed on the screen.
Fourth, display a menu in the shell program that allows adding (A) an entry to the phone book, deleting (D) an entry from the phone book, modifying (M) an entry in the phone book, displaying (I) an entry in the phone book, displaying (P) all entries in the phone book in sorted order, or exiting (X) the program. Accept either an uppercase or lowercase letter for the menu option. For adding, deleting, or modifying an entry, add additional code that checks the “logname” of the user running the shell program and ensures that the user is a member of the class (in the /etc/passwd personally created password file). For security reasons, you may need to use the passwd file included as an attachment in the assignment or use your own. This program continues until the exit choice is entered.
Other General Requirements:
In addition to including the above-mentioned functionality, make sure you incorporate each of the following elements in order to receive full credit:
1. Inclusion of a trap statement at the top of the program and testing to ensure that it works.
2. Completely functional business logic for each of the menu options (i.e., adding, deleting, modifying, displaying).
3. Use of functions throughout- such as for each menu option
4. Use of Linux commands: sed and conditional statements (e.g, if and do or while)
5. Upload of both the actual shell program code and three or more screenshots illustrating the functionality of the menu options
Grading Rubric
Criterion
Point Value (%)
Below Average (0% of value)
Average (50% to 70% of value)
Above Average (80% to 90% of value)
Superior (90% to 100% of value)
Input parameter validation
10
None
Only number args or file checked
Incomplete checking of arguments and file
Number args and file size and format checked
Input file complete
5
None
Input file exists w/less than 10 entries
Input file exists w/less than 20 entries
Input file exists with 20+ entries properly formatted
Trap included
5
None
None
Trap statement coded but not demoed
Trap statement coded and demoed
Menu included
10
None
Partial list (1-3) of menu items coded and displayed
All menu items coded and displayed with cosmetic issues
All menu items coded and displayed in user-friendly manner. Lower- and upper-case inputs accepted.
Business logic complete
20
None
1 or 2 functions partially complete and working (display, add,modify, delete)
1 or 2 functions complete (display, add,modify, delete)
4 functions (Display, add, modify, delete) complete and working
Linux command usage
20
None
Limited use of functions, but no usage of sed or conditional statements
Good use of functions, but limited usage of conditional statements
Complete use of 1) functions, 2) sed, 3) if and do/while conditional statements
Output complete
15
None
Code included, 0-1 screenshots
Code included, 2 screenshots
3 or more screenshots, code included
Writing quality
15
None
Major English faults, poor labelling
Clear English, few faults, partial commenting,good labelling
Fully commented code, labelled screenshots, clear English, and no faults
Total
100
Instructions PRGRAMMING IN UNIX
This project incorporates many skills learned throughout this course. Prepare the shell program described below using a modular approach that uses functions where appropriate.
First, identify the password file attached to this project, the one used in assignment 5, or create your own as desired. It will be used in this project. Make sure it at least has your own “logname” username of yourself in the file.
Second, create an office telephone directory file containing three columns of the last name, first name, and phone number of at least 10 individuals. Then create a shell program that accepts either one (last name) or two (last name and first name) arguments. Check to ensure that one or two arguments are on the command line. If there is only one argument, display a message informing the user that more than one entry might be returned from the phone book. Exit the program if there are less than one or more than two arguments.
Third, after checking on the arguments, display a prompt asking what phone book directory file to search. Test to ensure that the entry is a valid regular file that is not zero bytes in length. If not a regular file, exit the program with an appropriate message to the user on the screen. Then check to see that there are three columns in the file. If there are not three columns, display a message indicating that the file does not contain a configuration consistent with a phone book and exit the program with an appropriate message displayed on the screen.
Fourth, display a menu in the shell program that allows adding (A) an entry to the phone book, deleting (D) an entry from the phone book, modifying (M) an entry in the phone book, displaying (I) an entry in the phone book, displaying (P) all entries in the phone book in sorted order, or exiting (X) the program. Accept either an uppercase or lowercase letter for the menu option. For adding, deleting, or modifying an entry, add additional code that checks the “logname” of the user running the shell program and ensures that the user is a member of the class (in the /etc/passwd personally created password file). For security reasons, you may need to use the passwd file included as an attachment in the assignment or use your own. This program continues until the exit choice is entered.
Other General Requirements:
In addition to including the above-mentioned functionality, make sure you incorporate each of the following elements in order to receive full credit:
1. Inclusion of a trap statement at the top of the program and testing to ensure that it works.
2. Completely functional business logic for each of the menu options (i.e., adding, deleting, modifying, displaying).
3. Use of functions throughout- such as for each menu option
4. Use of Linux commands: sed and conditional statements (e.g, if and do or while)
5. Upload of both the actual shell program code and three or more screenshots illustrating the functionality of the menu options
Grading Rubric
Criterion
Point Value (%)
Below Average (0% of value)
Average (50% to 70% of value)
Above Average (80% to 90% of value)
Superior (90% to 100% of value)
Input parameter validation
10
None
Only number args or file checked
Incomplete checking of arguments and file
Number args and file size and format checked
Input file complete
5
None
Input file exists w/less than 10 entries
Input file exists w/less than 20 entries
Input file exists with 20+ entries properly formatted
Trap included
5
None
None
Trap statement coded but not demoed
Trap statement coded and demoed
Menu included
10
None
Partial list (1-3) of menu items coded and displayed
All menu items coded and displayed with cosmetic issues
All menu items coded and displayed in user-friendly manner. Lower- and upper-case inputs accepted.
Business logic complete
20
None
1 or 2 functions partially complete and working (display, add,modify, delete)
1 or 2 functions complete (display, add,modify, delete)
4 functions (Display, add, modify, delete) complete and working
Linux command usage
20
None
Limited use of functions, but no usage of sed or conditional statements
Good use of functions, but limited usage of conditional statements
Complete use of 1) functions, 2) sed, 3) if and do/while conditional statements
Output complete
15
None
Code included, 0-1 screenshots
Code included, 2 screenshots
3 or more screenshots, code included
Writing quality
15
None
Major English faults, poor labelling
Clear English, few faults, partial commenting,good labelling
Fully commented code, labelled screenshots, clear English, and no faults
Total
100
Explanation / Answer
#!/bin/sh
# Name of phonebook
BOOK="phonebook.txt"
# Use of a case statement to offer a 5 item menu
echo “ Menu 1. Add an entry 2. Display all matches to a string 3. Sort and display the file 4. Delete all entries that match a string 5. Quit to Unix Enter your option #: c”
read choice
case “$choice” in
1) add;;
2) list;;
3) find;;
4) delete;;
5) exit ;;
*) echo “Invalid option” # ;; not needed for last option
esac
exit=0
while [ $exit -ne 1 ]
do
echo "operation you want?"
echo -e "add, list, find, delete, exit: "
read answer
if [ "$answer" = "add" ]
then
./add.sh
elif [ "$answer" = "list" ]
then
./list.sh
elif [ "$answer" = "find" ]
then
./find.sh
elif [ "$answer" = "delete" ]
then
./delete.sh
elif [ "$answer" = "exit" ]
then
exit=1
else
echo "command not available."
fi
done
exit 0