Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help writing a simple bash shell script! My electricity went out (typing on phone) so I really need help, please. Thanks!!! These are the

Need help writing a simple bash shell script! My electricity went out (typing on phone) so I really need help, please. Thanks!!!

These are the files I need to create for this assignment (Note: asg1.cmds is created by our professor when grading so I don't need to make that one):

image text in transcribed

---------- Quick information on how the bash shell script will take photo information ----------

image text in transcribed

---------- Information for how you can make the bash script itself: ----------

image text in transcribed

image text in transcribed

image text in transcribed

assign1.sh - the main file which is to be initially invoked create.bash - logic for the Create option read.bash - logic for the Read option update.bash - logic for the Update option delete.bash - logic for the Delete option asgl.output-output from running asg1.cmds data/queries.log-log entries from running asg1.cmds For this assignment, you will use bash to create a simple photo inventory system. Your system will store basic information about photos and allow the user to create, read, update, and delete these photo items. The assignment requires only the utilities used so far in the lecture notes. Further, you may not use sed, awk, find, grep, Python, perl, or any other programming language, scripting language, or other tools not otherwise explicitly permitted. Storing Photo Information We will be writing a script that maintains photo metadata stored in text files ending with the extension .photo. 1. Files will be stored in a directory named data, located within the same directory as your shell script. 2. Each file will be named beginning with the letter p, followed by a unique photo number, an integer (henceforth referred to as photo_num), and ending with the extension .photo. 3. Every photo file consists of at exactly four lines, in the following format: a. photo_file - where the actual image is located. Could be an absolute reference starting with "/", or a relative reference starting with ../". b. photo_date-year month day separated by exactly one space. Each will be a number, such as 2021 1 15. C. photo_location - where the photo was taken. Just a string for us, likely to contain spaces. Could be something like New York City. d. photo_names zero or more names of people in the photo. 4. Here is a sample file named p23.photo: /home/abc123/picts/2004-australia-001.jpg 2004 124 Sydney, Australia Nicole Kidman, Hugh Jackman Script Execution When the script is run, the following should occur. 1. Upon running your script, the user should be presented with the following menu: Enter one of the following actions or press CTRL-D to exit. create a new photo item R - read an existing photo item U - update an existing photo item D - delete an existing photo item Q - quit 2. The user then enters a corresponding one-character selection (either upper or lowercase entries should be permissible), leading to one of the following actions: a. C: Create a new photo item i. From the terminal, prompt for the following fields, one at a time, each on its own line: 1. Photo number: such as 23 (must be in the range 1 to 99999). 2. Photo file location: such as /home/bk1740/temp/pic1.jpg. If it does not exist, print an error message and ask again. 3. Photo year: such as 2021 (must in the range 1950 to 2050) 4. Photo month: such as 1 (must be from 1 to 12) 5. Photo day: such as 30 (must be from 1 to 31) 6. Photo location: such as Sydney, Australia (required) 7. Photo names: such as Nicole Kidman, Hugh Jackman (optional) ii. Validate that the photo number is unique before asking for the photo file. If not, print the error "p.photo already exists" and return to the main prompt, where is the photo number above. iii. If the year, month or day is out of range, print an error message like "Month 25 is not in the range 1 to 12" and continue asking for it until it is range. iv. Create the data directory if it does not exist (see below). v. Using the values entered by the user, create a new file in the data subdirectory. vi. Update data/queries.log by adding a CREATED line entry. b. R: Read an existing photo item i. Prompt the user for a photo number. ii. Validate that the photo file exists. If not, print the error "p.photo does not exist" and return to the main prompt, where is the photo number above. iii. Print the photo's information in the following format: Photo: photo_num File: photo_file Date: photo_month / photo_day / photo_year Location: photo_location Names: photo names (possibly blank) c. U: Update an existing photo item i. Prompt for the photo number. ii. Validate that the photo file exists. If not, print the error "p.photo does not exist" and return to the main prompt, where is the photo number above. iii. Prompt for the following values (similar to create) 1. Photo year: such as 2021 (must in the range 1950 to 2050) 2. Photo month: such as 1 (must be from 1 to 12) 3. Photo day: such as 30 (must be from 1 to 31) 4. Photo location: such as Sydney, Australia 5. Photo names: such as Nicole Kidman, Hugh Jackman iv. Using the values entered by the user, search for the specified item in the data subdirectory using the given photo number. v. Do not allow the photo file location to be changed. vi. Update each of the corresponding fields based on the user's input. If the user input is blank for a particular field (except for the item number), keep the existing value and display the value being used. vii. Update data/queries.log by adding an UPDATED line. Show the new values even if the user left it blank. d. D: Delete an existing photo item i. Prompt the user for a photo number. ii. Validate that the photo file exists. If not, print the error "p.photo does not exist" and return to the main prompt, where is the photo number entered above. iii. Update data/queries.log by adding a DELETED line. e. Q: Quit f. If any other character is entered at the main menu, print the following error message, and continue with the script: "ERROR: invalid option: 'X'", where x is the invalid entry. 3. After an action is completed, display the menu again. This should proceed indefinitely until they press Q or CTRL-D, or the end of the input is reached. assign1.sh - the main file which is to be initially invoked create.bash - logic for the Create option read.bash - logic for the Read option update.bash - logic for the Update option delete.bash - logic for the Delete option asgl.output-output from running asg1.cmds data/queries.log-log entries from running asg1.cmds For this assignment, you will use bash to create a simple photo inventory system. Your system will store basic information about photos and allow the user to create, read, update, and delete these photo items. The assignment requires only the utilities used so far in the lecture notes. Further, you may not use sed, awk, find, grep, Python, perl, or any other programming language, scripting language, or other tools not otherwise explicitly permitted. Storing Photo Information We will be writing a script that maintains photo metadata stored in text files ending with the extension .photo. 1. Files will be stored in a directory named data, located within the same directory as your shell script. 2. Each file will be named beginning with the letter p, followed by a unique photo number, an integer (henceforth referred to as photo_num), and ending with the extension .photo. 3. Every photo file consists of at exactly four lines, in the following format: a. photo_file - where the actual image is located. Could be an absolute reference starting with "/", or a relative reference starting with ../". b. photo_date-year month day separated by exactly one space. Each will be a number, such as 2021 1 15. C. photo_location - where the photo was taken. Just a string for us, likely to contain spaces. Could be something like New York City. d. photo_names zero or more names of people in the photo. 4. Here is a sample file named p23.photo: /home/abc123/picts/2004-australia-001.jpg 2004 124 Sydney, Australia Nicole Kidman, Hugh Jackman Script Execution When the script is run, the following should occur. 1. Upon running your script, the user should be presented with the following menu: Enter one of the following actions or press CTRL-D to exit. create a new photo item R - read an existing photo item U - update an existing photo item D - delete an existing photo item Q - quit 2. The user then enters a corresponding one-character selection (either upper or lowercase entries should be permissible), leading to one of the following actions: a. C: Create a new photo item i. From the terminal, prompt for the following fields, one at a time, each on its own line: 1. Photo number: such as 23 (must be in the range 1 to 99999). 2. Photo file location: such as /home/bk1740/temp/pic1.jpg. If it does not exist, print an error message and ask again. 3. Photo year: such as 2021 (must in the range 1950 to 2050) 4. Photo month: such as 1 (must be from 1 to 12) 5. Photo day: such as 30 (must be from 1 to 31) 6. Photo location: such as Sydney, Australia (required) 7. Photo names: such as Nicole Kidman, Hugh Jackman (optional) ii. Validate that the photo number is unique before asking for the photo file. If not, print the error "p.photo already exists" and return to the main prompt, where is the photo number above. iii. If the year, month or day is out of range, print an error message like "Month 25 is not in the range 1 to 12" and continue asking for it until it is range. iv. Create the data directory if it does not exist (see below). v. Using the values entered by the user, create a new file in the data subdirectory. vi. Update data/queries.log by adding a CREATED line entry. b. R: Read an existing photo item i. Prompt the user for a photo number. ii. Validate that the photo file exists. If not, print the error "p.photo does not exist" and return to the main prompt, where is the photo number above. iii. Print the photo's information in the following format: Photo: photo_num File: photo_file Date: photo_month / photo_day / photo_year Location: photo_location Names: photo names (possibly blank) c. U: Update an existing photo item i. Prompt for the photo number. ii. Validate that the photo file exists. If not, print the error "p.photo does not exist" and return to the main prompt, where is the photo number above. iii. Prompt for the following values (similar to create) 1. Photo year: such as 2021 (must in the range 1950 to 2050) 2. Photo month: such as 1 (must be from 1 to 12) 3. Photo day: such as 30 (must be from 1 to 31) 4. Photo location: such as Sydney, Australia 5. Photo names: such as Nicole Kidman, Hugh Jackman iv. Using the values entered by the user, search for the specified item in the data subdirectory using the given photo number. v. Do not allow the photo file location to be changed. vi. Update each of the corresponding fields based on the user's input. If the user input is blank for a particular field (except for the item number), keep the existing value and display the value being used. vii. Update data/queries.log by adding an UPDATED line. Show the new values even if the user left it blank. d. D: Delete an existing photo item i. Prompt the user for a photo number. ii. Validate that the photo file exists. If not, print the error "p.photo does not exist" and return to the main prompt, where is the photo number entered above. iii. Update data/queries.log by adding a DELETED line. e. Q: Quit f. If any other character is entered at the main menu, print the following error message, and continue with the script: "ERROR: invalid option: 'X'", where x is the invalid entry. 3. After an action is completed, display the menu again. This should proceed indefinitely until they press Q or CTRL-D, or the end of the input is reached<><><><><><><><><><><><><><><><>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Outlook 2023

Authors: James Holler

1st Edition

B0BP9P1VWJ, 979-8367217322

More Books

Students also viewed these Databases questions

Question

The company openly shares plans and information with employees.

Answered: 1 week ago