Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

do not care about minitester.sh ,just do the question please, the arguments are assumed to be in oder Ex. 2 A bash script for file

image text in transcribedimage text in transcribedimage text in transcribed

do not care about minitester.sh ,just do the question please,

the arguments are assumed to be in oder

Ex. 2 A bash script for file search and content display (12 Points) Search is a very essential form of interaction with the contents stored in a file system. In this task, you will write a bash shell script seeker.sh that will look for file names with a specific string in the file name and optionally display its contents to the screen. The usage syntax for the script is as follows. $ /seeker.sh [-c] [-a] pattern [path] The options arguments in square brackets are optional, and their intent is as follows. -c indicates that the script should display the contents of the file. Otherwise only the absolute path to the file (including file name is displayed to the screen. -a indicates that if there are multiple matching files, the output should include all of them. Otherwise only (any) one of the file is included in the output. path is the absolute path to the directory under which the script should look for the files. If this argument is not passed to the script, it is expected to look for files under the "current directory". pattern is a string that you want the script to look for in the name of a file (NOT contents of the file). For example if pattern is msg, it should match the file names mymsg.txt, msg.txt, random.msg, lastmsgs.txt, etc. An example output of this script is as below. $ /seeker.sh-C-a msg /mydata/scribbles ==== Contents of: /mydata/scribbles/msg2.txt ==== Hi, I am msg2.txt Not all those who wander are lost. ==== Contents of: /mydata/scribbles/msg.txt ==== Hello there, I am msg.txt 2 Points for writing code with proper (readability) indentation and writing necessary comments (required to un- derstand the logic, etc.) in the code. 1. Use vi to create your script in mimi.cs.mcgill.ca. 2.Ensure that your script can be executed using bash shell. 3.2 Points) Ensure that your script is passed proper arguments. pattern is the only mandatory input to the script. An appropriate error and usage message should be raised if proper arguments are not passed into the script. See examples below. $ ./seeker.sh Error missing the pattern argument. Usage . / seeker.sh [-c] [-a] pattern [path] $ ./seeker.sh -C Error missing the pattern argument. Usage . /seeker.sh [-c] [-a] pattern [path] $ ./seeker.sh -a Error missing the pattern argument. Usage /seeker.sh [-c] [-a) pattern [path] $ ./seeker.sh -c -a Error missing the pattern argument. Usage ./seeker.sh [-c] [-a] pattern [path] 4.(1 Point) If the directory passed as argument to the script does not exist, the script should display this fact. $ ./seeker.sh msg osuchdir Error osuchdir is not a valid directory $ ./seeker.sh -a msg osuchdir Error osuchdir is not a valid directory 5.(1 Point) If script cannot find any files with the specified pattern in its name, it should display this information. $ ./seeker.sh -a meow /etc/cron.d Unable to locate any files that has pattern meow in its name in /etc/cron.d. 6.(1 Point) When -a option is not passed, include only (any) one matching file in the output. $ ./seeker.sh msg /scribbles/messages /scribbles/messages/msg2.txt 7.(1 Point) When -a option is passed, include all the files that match the pattern $ ./seeker.sh -a msg /scribbles/messages /scribbles/messages/msg2.txt /scribbles/messages/msg.txt 8.(2 Points) When -c option is passed, contents of the files must be displayed $ ./seeker.sh -c msg /scribbles/messages - Contents of: /scribbles/messages/msg2.txt --- Hi, I am msg2.txt Not all those who wander are lost. $ ./seeker.sh -c -a msg /scribbles/messages ==== Contents of: /scribbles/messages/msg2.txt --- Hi, I am msg2.txt Not all those who wander are lost. - Contents of: /scribbles/messages/msg.txt --- Hello there, I am msg.txt 9.(2 Points) When path argument to indicate the directory to look for files is not passed, search in the current directory. $ cd /scribbles/messages $ ./seeker.sh-C-a msg === Contents of: /scribbles/messages/msg2.txt ==== Hi, I am msg2.txt Not all those who wander are lost. ==== Contents of: /scribbles/messages/msg.txt ==== Hello there, I am msg.txt WHAT TO HAND IN Turn in the 2 shell scripts tarzan.sh and seeker.sh, named properly (so that the TA can identify which script is for which question. You do not have to zip all of the scripts together. MISC. INFORMATION There is a tester script mini2tester.sh that is provided with the assignment that you can use to test how your scripts are behaving. TAs will be using the exact same tester script to grade your assignment. $ ./mini 2tester.sh However, it is recommended that when you start writing your scripts, test it yourself first with each option and arguments such as the ones given in the above examples. Once you are fairly confident that your script is working, you can test it using the tester script You can compare the output produced by running the mini tester on your scripts to that produced by the mini tester on the solution scripts which is given in mini2tester.out.txt. Other than the names of directories used by the tester scripts, the remaining contents should match. FOOD FOR THOUGHT! The following discussion is meant to encourage you to search independently for creative and optimal ways to perform rudimentary tasks with less effort and does not impact the points that you can achieve in the above questions. Will your script work for both $ ./seeker.sh -c -a msg and $ ./seeker.sh -a -c msg If not, can you think of a way to address it? Is your approach scalable and easy to maintain if we have three different options to pass? Does shell provide other efficient mechanisms to read options passed to a script? Ex. 2 A bash script for file search and content display (12 Points) Search is a very essential form of interaction with the contents stored in a file system. In this task, you will write a bash shell script seeker.sh that will look for file names with a specific string in the file name and optionally display its contents to the screen. The usage syntax for the script is as follows. $ /seeker.sh [-c] [-a] pattern [path] The options arguments in square brackets are optional, and their intent is as follows. -c indicates that the script should display the contents of the file. Otherwise only the absolute path to the file (including file name is displayed to the screen. -a indicates that if there are multiple matching files, the output should include all of them. Otherwise only (any) one of the file is included in the output. path is the absolute path to the directory under which the script should look for the files. If this argument is not passed to the script, it is expected to look for files under the "current directory". pattern is a string that you want the script to look for in the name of a file (NOT contents of the file). For example if pattern is msg, it should match the file names mymsg.txt, msg.txt, random.msg, lastmsgs.txt, etc. An example output of this script is as below. $ /seeker.sh-C-a msg /mydata/scribbles ==== Contents of: /mydata/scribbles/msg2.txt ==== Hi, I am msg2.txt Not all those who wander are lost. ==== Contents of: /mydata/scribbles/msg.txt ==== Hello there, I am msg.txt 2 Points for writing code with proper (readability) indentation and writing necessary comments (required to un- derstand the logic, etc.) in the code. 1. Use vi to create your script in mimi.cs.mcgill.ca. 2.Ensure that your script can be executed using bash shell. 3.2 Points) Ensure that your script is passed proper arguments. pattern is the only mandatory input to the script. An appropriate error and usage message should be raised if proper arguments are not passed into the script. See examples below. $ ./seeker.sh Error missing the pattern argument. Usage . / seeker.sh [-c] [-a] pattern [path] $ ./seeker.sh -C Error missing the pattern argument. Usage . /seeker.sh [-c] [-a] pattern [path] $ ./seeker.sh -a Error missing the pattern argument. Usage /seeker.sh [-c] [-a) pattern [path] $ ./seeker.sh -c -a Error missing the pattern argument. Usage ./seeker.sh [-c] [-a] pattern [path] 4.(1 Point) If the directory passed as argument to the script does not exist, the script should display this fact. $ ./seeker.sh msg osuchdir Error osuchdir is not a valid directory $ ./seeker.sh -a msg osuchdir Error osuchdir is not a valid directory 5.(1 Point) If script cannot find any files with the specified pattern in its name, it should display this information. $ ./seeker.sh -a meow /etc/cron.d Unable to locate any files that has pattern meow in its name in /etc/cron.d. 6.(1 Point) When -a option is not passed, include only (any) one matching file in the output. $ ./seeker.sh msg /scribbles/messages /scribbles/messages/msg2.txt 7.(1 Point) When -a option is passed, include all the files that match the pattern $ ./seeker.sh -a msg /scribbles/messages /scribbles/messages/msg2.txt /scribbles/messages/msg.txt 8.(2 Points) When -c option is passed, contents of the files must be displayed $ ./seeker.sh -c msg /scribbles/messages - Contents of: /scribbles/messages/msg2.txt --- Hi, I am msg2.txt Not all those who wander are lost. $ ./seeker.sh -c -a msg /scribbles/messages ==== Contents of: /scribbles/messages/msg2.txt --- Hi, I am msg2.txt Not all those who wander are lost. - Contents of: /scribbles/messages/msg.txt --- Hello there, I am msg.txt 9.(2 Points) When path argument to indicate the directory to look for files is not passed, search in the current directory. $ cd /scribbles/messages $ ./seeker.sh-C-a msg === Contents of: /scribbles/messages/msg2.txt ==== Hi, I am msg2.txt Not all those who wander are lost. ==== Contents of: /scribbles/messages/msg.txt ==== Hello there, I am msg.txt WHAT TO HAND IN Turn in the 2 shell scripts tarzan.sh and seeker.sh, named properly (so that the TA can identify which script is for which question. You do not have to zip all of the scripts together. MISC. INFORMATION There is a tester script mini2tester.sh that is provided with the assignment that you can use to test how your scripts are behaving. TAs will be using the exact same tester script to grade your assignment. $ ./mini 2tester.sh However, it is recommended that when you start writing your scripts, test it yourself first with each option and arguments such as the ones given in the above examples. Once you are fairly confident that your script is working, you can test it using the tester script You can compare the output produced by running the mini tester on your scripts to that produced by the mini tester on the solution scripts which is given in mini2tester.out.txt. Other than the names of directories used by the tester scripts, the remaining contents should match. FOOD FOR THOUGHT! The following discussion is meant to encourage you to search independently for creative and optimal ways to perform rudimentary tasks with less effort and does not impact the points that you can achieve in the above questions. Will your script work for both $ ./seeker.sh -c -a msg and $ ./seeker.sh -a -c msg If not, can you think of a way to address it? Is your approach scalable and easy to maintain if we have three different options to pass? Does shell provide other efficient mechanisms to read options passed to a script

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

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions