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

Introduction to UNIX with Shell Scripting 1) This is a multi-faceted project. Wr

ID: 3849674 • Letter: I

Question

Introduction to UNIX with Shell Scripting

1) This is a multi-faceted project. Write a script that will take the information from the data file and make the output as shown below. Also, write a menu that will allow the printing, addition or deletion of a book from the data file.

2) Requirements of the script:

a) You can use any shell, but you must identify the script on the first line.

b) Must start with the input data files exactly formatted as shown below.

c) Write a menu system, using sub-functions, that will allow the following functionality:

a. Format and send the data to the screen, as formatted in section 4.

b. Print to classroom printer.

c. Add a book to the database.

d. Remove a book from the database.

d) The menu must show on the screen in color. Please use a different color for each function.

e) Fully document (comment) all aspects of your script. Explain what you're doing. Points will be deducted for any undocumented entries.

f) A looping structure MUST be used to process the data files someplace in the script.

g) The file output must be sorted by ISBN, the third column. h) Make sure the ISBN numbers are formatted like the example output.

i) Make sure that when the script is run that the current date is shown.

j) Your script MUST be called “project2.ksh”.

k) The data file MUST be called “books.data”

3) The contents of the initial data file.

Clive Cussler,Ghost Ship,9780399167317

Clive Cussler,Bootlegger,9780399167294

James Patterson,Invisible,9780316405348

James Patterson,Gone,9781455515844

James Rollins,Map of Bones,9780062017857

Michael Connelly,The Lincoln Lawyer,9781455516346

David Baldacci, The Escape,9781478984344

CIS129 Project 2

4) The output should look like:

****************************************

* CIS129 Project 2 Your Name *

* Current date and time *

****************************************

Author Name of Book ISBN

Clive Cussler Ghost Ship 978-0399-16731-7

Clive Cussler Bootlegger 978-0399-16729-4

James Patterson Invisible 978-0316-40534-8

James Patterson Gone 978-1455-51584-4

James Rollins Map of Bones 978-0062-01785-7

Michael Connelly The Lincoln Lawyer 978-1455-51634-6

David Baldacci The Escape 978-1478-98434-4

5) The menu should look something like.

****************************************

* CIS129 Project 2 Menu *

* Your Name *

* Current date and time *

****************************************

1. Show the book inventory to the screen.

2. Print the book inventory.

3. Add a book to the inventory.

4. Remove a book from the inventory.

Please select a number from the list below (1 – 4)

Explanation / Answer

NOTE: Once you run the script type ctrl+c to terminate because the script will infinitely show the menu options to manipulate the book inventory.

Currently the printInventory() function will send the output to your default class printer, but if you want to change to another printer you have to make changes accordingly.

Write your name wherever you see <Fill your name>

Code:
#!/bin/ksh

# program to manage book inventory
# script name: project2.ksh

# function to print the inventory in formatted output on the console
showInventory()
{
   # printing the formatted output
   echo '****************************************'
   echo '* CIS129 Project 2 <Fill Your Name> *'
   echo "`date`"
   echo '****************************************'
   printf "%-25s %-25s %-25s " "Author" "Name of Book" "ISBN">/tmp/outfile

   # fetching the lines from file books.data and printing in formatted output to console
   while read line
   do
       echo $line|awk -F"," '{isbn=substr($3,1,3) "-" substr($3,4,4) "-" substr($3,8,5) "-" substr($3,13,1); printf "%-25s %-25s %-25s ", $1, $2, isbn;}'>>/tmp/outfile
   done<books.data

   # displaying the formatted output
   cat /tmp/outfile

}

# function to print the inventory to printer
printInventory()
{
   # printing the formatted output
   echo '****************************************'
   echo '* CIS129 Project 2 <Fill Your Name> *'
   echo "`date`"
   printf "%-25s %-25s %-25s " "Author" "Name of Book" "ISBN">/tmp/outfile

   # fetching the lines from file books.data and printing in formatted output to console
   while read line
        do    
                echo $line|awk -F"," '{isbn=substr($3,1,3) "-" substr($3,4,4) "-" substr($3,8,5) "-" substr($3,13,1); printf "%-25s %-25s %-25s ", $1, $2, isbn;}'>>/tmp/outfile
        done<books.data
  
   # check the below command as i do not have printer configured to my system
   cat /tmp/outfile|lpr
}

# add the book to database
addbook()
{
   # enter the author name want to add
   echo "Enter the author name: "
   read author
   # enter the book name to add
   echo "Enter the Name of Book: "
   read book
   # enter the ISBN of book to add
   echo "Enter the ISBN: "
   read isbn
   # adding the new book information to books.data database
   echo "$author,$book,$isbn">>books.data
}

# remove a particular book from database
removebook()
{
   # getting the book user want to delete
   echo "Enter the book name to delete: "
   read book
   # removing the book user want to delete and redirecting to temporary file
   grep -v "$book" books.data>/tmp/outfile
   # updating temporary file to books.data database  
   cat /tmp/outfile>books.data
}


while true
do
   # displaying the menu with options
   echo '****************************************'
   echo '* CIS129 Project 2 Menu *'
   echo '* <Fill your name here> *'
   echo "`date`"
   echo '****************************************'
   echo -e "e[1;33m 1. Show the book inventory to the screen. e[0m"
   echo -e "e[1;34m 2. Print the book inventory. e[0m"
   echo -e "e[1;35m 3. Add a book to the inventory. e[0m"
   echo -e "e[1;36m 4. Remove a book from the inventory. e[0m"

   # Ask user for the choice of menu and call appropriate functions
   echo 'Please select a number from the list below (1 – 4) '
   read choice

   if [ $choice == 1 ]
   then
       showInventory
   elif [ $choice == 2 ]
   then
       printInventory
   elif [ $choice == 3 ]
   then
       addbook
   elif [ $choice == 4 ]
   then
       removebook
   fi  

done


Execution and output:
Unix Terminal> ./project2.ksh
****************************************
* CIS129 Project 2 Menu *
* <Fill your name here> *
Thu Jun 8 20:24:59 IST 2017
****************************************
1. Show the book inventory to the screen.
2. Print the book inventory.
3. Add a book to the inventory.
4. Remove a book from the inventory.
Please select a number from the list below (1 – 4)
1
****************************************
* CIS129 Project 2 <Fill Your Name> *
Thu Jun 8 20:25:01 IST 2017
****************************************
Author                      Name of Book                ISBN                   
Clive Cussler               Ghost Ship                  978-0399-16731-7       
Clive Cussler               Bootlegger                  978-0399-16729-4       
James Patterson             Invisible                   978-0316-40534-8       
James Patterson             Gone                        978-1455-51584-4       
James Rollins               Map of Bones                978-0062-01785-7       
Michael Connelly            The Lincoln Lawyer          978-1455-51634-6       
David Baldacci              The Escape                 978-1478-98434-4       
****************************************
* CIS129 Project 2 Menu *
* <Fill your name here> *
Thu Jun 8 20:25:02 IST 2017
****************************************
1. Show the book inventory to the screen.
2. Print the book inventory.
3. Add a book to the inventory.
4. Remove a book from the inventory.
Please select a number from the list below (1 – 4)
3
Enter the author name:
Vijay Krishna
Enter the Name of Book:
The Peaceful Warrior
Enter the ISBN:
1234567891231
****************************************
* CIS129 Project 2 Menu *
* <Fill your name here> *
Thu Jun 8 20:25:38 IST 2017
****************************************
1. Show the book inventory to the screen.
2. Print the book inventory.
3. Add a book to the inventory.
4. Remove a book from the inventory.
Please select a number from the list below (1 – 4)
1
****************************************
* CIS129 Project 2 <Fill Your Name> *
Thu Jun 8 20:25:40 IST 2017
****************************************
Author                      Name of Book                ISBN                   
Clive Cussler               Ghost Ship                  978-0399-16731-7       
Clive Cussler               Bootlegger                  978-0399-16729-4       
James Patterson             Invisible                   978-0316-40534-8       
James Patterson             Gone                        978-1455-51584-4       
James Rollins               Map of Bones                978-0062-01785-7       
Michael Connelly            The Lincoln Lawyer          978-1455-51634-6       
David Baldacci              The Escape                 978-1478-98434-4       
Vijay Krishna               The Peaceful Warrior        123-4567-89123-1       
****************************************
* CIS129 Project 2 Menu *
* <Fill your name here> *
Thu Jun 8 20:25:40 IST 2017
****************************************
1. Show the book inventory to the screen.
2. Print the book inventory.
3. Add a book to the inventory.
4. Remove a book from the inventory.
Please select a number from the list below (1 – 4)
4
Enter the book name to delete:
The Peaceful Warrior
****************************************
* CIS129 Project 2 Menu *
* <Fill your name here> *
Thu Jun 8 20:25:54 IST 2017
****************************************
1. Show the book inventory to the screen.
2. Print the book inventory.
3. Add a book to the inventory.
4. Remove a book from the inventory.
Please select a number from the list below (1 – 4)
1
****************************************
* CIS129 Project 2 <Fill Your Name> *
Thu Jun 8 20:25:55 IST 2017
****************************************
Author                      Name of Book                ISBN                   
Clive Cussler               Ghost Ship                  978-0399-16731-7       
Clive Cussler               Bootlegger                  978-0399-16729-4       
James Patterson             Invisible                   978-0316-40534-8       
James Patterson             Gone                        978-1455-51584-4       
James Rollins               Map of Bones                978-0062-01785-7       
Michael Connelly            The Lincoln Lawyer          978-1455-51634-6       
David Baldacci              The Escape                 978-1478-98434-4       
****************************************
* CIS129 Project 2 Menu *
* <Fill your name here> *
Thu Jun 8 20:25:55 IST 2017
****************************************
1. Show the book inventory to the screen.
2. Print the book inventory.
3. Add a book to the inventory.
4. Remove a book from the inventory.
Please select a number from the list below (1 – 4)

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