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

I have found this question asked several times, and have tried using the previou

ID: 665436 • Letter: I

Question

I have found this question asked several times, and have tried using the previous solutions. However, I am stuck on the checking the password file to authenticate a user. Also, I am having an issue with the search function. I get an unexpected token `}' error at the end of the search function.

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:

Inclusion of a trap statement at the top of the program and testing to ensure that it works.

Completely functional business logic for each of the menu options (i.e., adding, deleting, modifying, displaying).

Use of functions throughout- such as for each menu option

Use of Linux commands: sed and conditional statements (e.g, if and do or while)

Upload of both the actual shell program code and three or more screenshots illustrating the functionality of the menu options

Explanation / Answer

#####SHELL CODE FOR PHONEBOOK_DIRECTORY

functionPHONEBOOK_ mainmenu

{
        echo “THE FOLLOWING ARE OPERATIONS MADE ON A PHONEBOOK”
        echo "A –ADD NEW USER"
        echo "D- DELETE ENTRY"
        echo "M- MODIFY ENTRY"
        echo "I- DISPLAY PARTICULAR ENTRY"
        echo "P- DISPLAY ALL ENTRIES IN SORTED ORDER"
        echo "X- QUIT THE PROGRAM"

}


function addUSER

{
        echo “ADDING USER TO THE PHONEBOOK”
        echo "ENTER USERS FIRST NAME.."
        read USER_firstName
        echo "ENTER USERS LAST NAME.."
        read USER_lastName
        USER_name=$USER_firstName" "$USER_lastName
        if [ `grep "$USER_name" /home/mobaxterm/Phonebook_Directory.txt | wc -l` -eq 0 ]
        then
                echo "ENTER 10 DIGIT PHONE NUMBER.."
                read USERnum
                if [ `echo "$USERnum" | wc -c` -eq 11 ]
                then
                        echo "$USER_name $USERnum" >> /home/mobaxterm/Phonebook_Directory.txt
                        rc=$?
                        if [ $rc -eq 0 ]
                        then
                                echo "SUCCESSFULLY ADDED THE USER TO THE PHONEBOOK”
                        else
                                echo "NOT POSSIBLE TO MAKE ENTRY IN THE PHONEBOOK."
                        fi
                else
                        echo "PLEASE ENTER 10-DIGIT VALID PHONE NUMBER.."
                fi
        else
                echo "$USER_name IS ALREADY EXISTS IN THE PHONEBOOK”
        fi
       PHONEBOOK_ mainmenu
}

function deleteUSER

{
        echo “DELETE AN ENTRY”
        echo "ENTER USERS FIRST NAME"
        read USER_firstName
        echo "ENTER USERS LAST NAME.."
        read USER_lastName
        USER_name=$USER_firstName" "$USER_lastName
        if [ `grep "$USER_name" /home/mobaxterm/Phonebook_Directory.txt | wc -l` -eq 0 ]
        then
                echo "NO ENTRY FOR THE SPECIFIED USER”
        else
                echo "COMFIRM THE USER PLEASE"
                PHONEBOOKnumbers=`grep "$USER_name" /home/mobaxterm/Phonebook_Directory.txt | awk -F ':' '{print $1}'`
                echo "$PHONEBOOKnumbers"
                read SAMconf
                PHONEBOOK_linenum=`grep -n "$SAMconf" /home/mobaxterm/Phonebook_Directory.txt | awk -F ':' '{print $1}'`
                sed $PHONEBOOK_linenum'd' /home/mobaxterm/Phonebook_Directory.txt > SAMtemp.txt

                SAMrc=$?
                if [ $SAMrc -eq 0 ]
                then
                        cat SAMtemp.txt > /home/mobaxterm/Phonebook_Directory.txt
                        rm SAMtemp.txt
                        echo "SUCCESSFULLY DELETED”
                else
                        echo "NOT POSSIBLE TO DELETE”

                fi
        fi
       PHONEBOOK_ mainmenu
}

function modifyUSER

{
        echo “EDITING IN THE PHONEBOOK"
        echo "ENTER USERS FIRST NAME"
        read USER_firstName
        echo "ENTER LAST NAME"
        read USER_lastName
        USER_name=$USER_firstName" "$USER_lastName
        if [ `grep "$USER_name" /home/mobaxterm/Phonebook_Directory.txt | wc -l` -eq 0 ]
        then
                echo "THERE IS NO ENTRY FOR THE SPECIFIED USER
        else
                echo "PLEASE CONFIRM THE USER"
                PHONEBOOKnumbers=`grep "$USER_name" /home/mobaxterm/Phonebook_Directory.txt | awk -F ':' '{print $1}'`
                echo "$PHONEBOOKnumbers"
                read conf
                PHONEBOOK_linenum=`grep -n "$conf" /home/mobaxterm/Phonebook_Directory.txt | awk -F ':' '{print $1}'`
                echo "ENTER USERS FIRST NAME"
                read newUSER_firstName
                echo "ENTER USERS LAST NAME"
                read newUSER_lastName
                SAMnewname=$newUSER_firstName" "$newUSER_lastName
                echo "$USER_name"
                echo "ENTER THE PHONE NUMBER.."
                read SAMnumb
                USER_linenum=$SAMnewname" "$SAMnumb
                echo "$USER_linenum"
                echo "$file"
                sed $PHONEBOOK_linenum'd' /home/mobaxterm/Phonebook_Directory.txt > SAMtemp.txt
                SAMrc=$?
                if [ $SAMrc -eq 0 ]
                then
                        echo "$USER_linenum" >>SAMtemp.txt
                        cat SAMtemp.txt > /home/mobaxterm/Phonebook_Directory.txt
                        echo "SUCESSFULLY EDITED"
                else
                        echo "NOT POSSIBLE TO EDIT
                fi
        fi
      PHONEBOOK_ mainmenu
}

function searchUSER

{
        echo “SERACHING ENTRY IN THE PHONEBOOK"
          echo "PHONEBOOK DIRECTORY TO SEARCH"

#GET THE PHONEBOOK DIRECTORY FROM USER
        read dir
        if [ -s /home/mobaxterm/$dir ]
        then
                  

     read USER_firstName

          echo "ENTER USERS LAST NAME"
          read USER_lastName

          if[ "$USER_firstName" = "" || "$USER_lastName" = "" ]
          then

echo "ENTER USERS FIRST NAME"

exit 0

        fi

          echo”NUMBER ARGUMNETS IS LESS”

USERname= USER_firstName” “USER_lastName
               if [ `grep "$USER_firstName" /home/mobaxterm/Phonebook_Directory.txt | wc -l` -eq 0 ]               

then
                        echo "No records present with the name : $USER_firstName"
                else
                       USERnumbs=`grep "$USER_firstName" /home/mobaxterm/Phonebook_Directory.txt | awk -F ':' '{print $1}'`
                        echo "$USERnumbs"
                fi
        if
          PHONEBOOK_ mainmenU

}

function PHONEBOOK_CLOSE

{
        exit 0
}

function displayUSER

{
        cat /home/mobaxterm/Phonebook_Directory.txt
       PHONEBOOK_ mainmenu
}


function PHONEBOOK_ DIRECTORY

{
       PHONEBOOK_ mainmenu
        while :
        do
                read PHONEBOOKoperation
                case $PHONEBOOKoperation in
                A)
                        addUSER ;;
                D)
                        deleteUSER;;
                M)
                        modifyUSER;;                       
                I)
                        searchUSER;;                       
                P)
                        displayUSER;;                       
                X)
                       PHONEBOOK_CLOSE;;                       
                *)
                        echo "INVALID CHOICE";;
                 esac
        done
}

echo "ENTER USER NAME.."
read ENTEREDusername
USERAuthorization=false
while read PASSWORDuserlist
do
        if [ "$PASSWORDuserlist" == "$ENTEREDusername" ]
        then
                USERAuthorization=true
                break
        fi
done < /home/mobaxterm/phonebook/password.dat


if [ "$USERAuthorization" = "true" ]
then
        echo "AUTHORISED USER"
        PHONEBOOK_ DIRECTORY
else
        echo "UNAUTHORISED USER. CANNOT OPEN PHONEBOOK"
fi