Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help to complete this assignment please guide me. So here is the assignme

ID: 3569989 • Letter: I

Question

I need help to complete this assignment please guide me.

So here is the assignment (UNIX Shell programming) :

Create an office telephone directory file containing three columns of the last name, first name, and phone number of at least 20 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.

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.

Third, 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. For adding, deleting, or modifying an entry, add additional code that checks the

Explanation / Answer

function mainmenu {
        echo "~~~~~~~~~~~~~~~Main Menu~~~~~~~~~~~~~~"
        echo "Enter A to add new number"
        echo "Enter D to delete number"
        echo "Enter M to modify the existing number"
        echo "Enter I to search for a number"
        echo "Enter P to disply all the numbers"
        echo "Enter X to exit"
        echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
}


function add {
        echo "~~~~~~~~~~ADD USER~~~~~~~~~~"
        echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        echo "Enter First name.."
        read firstName
        echo "Enter Last name.."
        read lastName
        name=$firstName" "$lastName
        if [ `grep "$name" /home/mobaxterm/Phonebook_Directory.txt | wc -l` -eq 0 ]
        then
                echo "Enter 10 digit number.."
                read num
                if [ `echo "$num" | wc -c` -eq 11 ]
                then
                        echo "$name $num" >> /home/mobaxterm/Phonebook_Directory.txt
                        rc=$?
                        if [ $rc -eq 0 ]
                        then
                                echo "User added successfully..."
                        else
                                echo "Could not add the user. Phonebook directory may be present.."
                        fi
                else
                        echo "Enter valid 10 digit number.."
                fi
        else
                echo "$name already exists.."
        fi
        mainmenu
}

function delete {
        echo "~~~~~~~~~~DELETE USER~~~~~~~~~~"
        echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        echo "Enter First name.."
        read firstName
        echo "Enter Last name.."
        read lastName
        name=$firstName" "$lastName
        if [ `grep "$name" /home/mobaxterm/Phonebook_Directory.txt | wc -l` -eq 0 ]
        then
                echo "User does not exist..."
        else
                echo "please confirm the user...(select complete line and press enter)"
                numbers=`grep "$name" /home/mobaxterm/Phonebook_Directory.txt | awk -F ':' '{print $1}'`
                echo "$numbers"
                read conf
                linenum=`grep -n "$conf" /home/mobaxterm/Phonebook_Directory.txt | awk -F ':' '{print $1}'`
                sed $linenum'd' /home/mobaxterm/Phonebook_Directory.txt > temp.txt

                rc=$?
                if [ $rc -eq 0 ]
                then
                        cat temp.txt > /home/mobaxterm/Phonebook_Directory.txt
                        rm temp.txt
                        echo "User deleted successfully..."
                else
                        echo "Could not delete the user. please select the entire line and press enter.."
                fi
        fi
        mainmenu
}

function modify {
        echo "~~~~~~~~~~MODIFY USER~~~~~~~~~~"
        echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        echo "Enter First name.."
        read firstName
        echo "Enter Last name.."
        read lastName
        name=$firstName" "$lastName
        if [ `grep "$name" /home/mobaxterm/Phonebook_Directory.txt | wc -l` -eq 0 ]
        then
                echo "User does not exist..."
        else
                echo "please confirm the user...(select complete line and press enter)"
                numbers=`grep "$name" /home/mobaxterm/Phonebook_Directory.txt | awk -F ':' '{print $1}'`
                echo "$numbers"
                read conf
                linenum=`grep -n "$conf" /home/mobaxterm/Phonebook_Directory.txt | awk -F ':' '{print $1}'`
                echo "Enter First name.."
                read newfirstName
                echo "Enter Last name.."
                read newlastName
                newname=$newfirstName" "$newlastName
                echo "$name"
                echo "Enter the number.."
                read numb
                newNum=$newname" "$numb
                echo "$newNum"
                echo "$file"
                sed $linenum'd' /home/mobaxterm/Phonebook_Directory.txt > temp.txt
                rc=$?
                if [ $rc -eq 0 ]
                then
                        echo "$newNum" >> temp.txt
                        cat temp.txt > /home/mobaxterm/Phonebook_Directory.txt
                        echo "Edited successfully..."
                else
                        echo "Could not edit.."
                fi
        fi
       mainmenu
        }

function search {
        echo "~~~~~~~~~~SEARCH USER~~~~~~~~~~"
        echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        echo "phonebook directory to search.."
        read dir
        if [ -s /home/mobaxterm/$dir ]
        then
                echo "Enter First name.."
                read firstName
                if [ `grep "$firstName" /home/mobaxterm/Phonebook_Directory.txt | wc -l` -eq 0 ]
                then
                        echo "No records present with the name : $firstName"
                else
                        numbs=`grep "$firstName" /home/mobaxterm/Phonebook_Directory.txt | awk -F ':' '{print $1}'`
                        echo "$numbs"
                fi
        if
        mainmenu
        }

function closephonebook {
        exit 0
        }

function allnumbers {
        cat /home/mobaxterm/Phonebook_Directory.txt
        mainmenu
        }


function phonebook {
        mainmenu
        while :
        do
                read operation
                case $operation in
                A)
                        add
                        ;;
                D)
                        delete
                        ;;
                M)
                        modify
                        ;;
                I)
                        search
                        ;;
                P)
                        allnumbers
                        ;;
                X)
                        closephonebook
                        ;;
                *)
                        echo "Invalid choice..."
                        ;;
                esac
        done
}

echo "Enter User Name.."
read username
Authorization=false
while read userlist
do
        if [ "$userlist" == "$username" ]
        then
                Authorization=true
                break
        fi
done < /home/mobaxterm/phonebook/password.dat


if [ "$Authorization" = "true" ]
then
        echo "Authorised User..."
        phonebook
else
        echo "Unauthorised User. Cannot open phonebook..."
fi

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote