Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Advanced Shell Scripting Lab Assignment 3-1 Part 1 Description: In this assignment, you will create a search utility by writing two shell scripts named .srchfile.sh.

 Advanced Shell Scripting Lab Assignment 3-1 Part 1 Description: In this assignment, you will create a search utility by writing two shell scripts named .srchfile.sh. and .srch.sh.. The script .srchfile.sh. will list all occurrences of a string found in a file. The script .srch.sh. will list all occurrences of a string in a file or all files in a specified directory. Actually, .srch.sh. will use the script .srchfile.sh. as if it were just another UNIX command to perform the actual search in a file. In other words, the script .srch.sh. needs to be able to use the script .srchfile.sh.. Therefore, this assignment recommends that the first script created be the .srchfile.sh. script. The script srch.sh, calls the srchfile.sh script. Requirements: . The shell script .srchfile.sh. must accept two command line arguments. 1. The script shall first print the name of the file being searched. 2. If there are one more instances of the string in the file, the script shall print each line that contains the matching string, along with the line number of the file. You may use the UNIX command .grep. in your script to do the actual search. In fact, .grep. can even print the line number if used with the appropriate option (see man page for grep). . If the user enters more or less than the required number of arguments, the script shall produce an error message and stop. . The first argument shall represent the string to be searched. . The second argument represents the name of the file to be searched. If the second argument is not a file, the script shall produce an error message and stop. . The script must be able to execute on the cs.franklin.edu machine . The script file name must be: .srchfile.sh.. . Both scripts must be located in $HOME/itec400/homework directory . The itec400 and homework directory permissions should be 705 . The script permissions should be 705 Sample Output: Sunny Day scenario, the srchfile.sh script is invoked searching for string .child. pattern in file .zombie.c. in ~dandrear/Fall_2013_Solutions directory: /export/home/dandrear/Winter_2014_Solutions>./srchfile.sh child zombie.c ------ File = /export/home/dandrear/Winter_2014_Solutions/zombie.c ------ 13: pid_t child_pid; 15: child_pid = fork (); 16: if (child_pid > 0) { Rainy Day scenario, script srchfield.sh is invoked with only one command line argument: /export/home/dandrear/Winter_2014_Solutions>./srchfile.sh then error: must provide 2 arguments usage: ./srchfile.sh search-pattern file Rainy Day scenario, script srchfile.sh is invoked with second command line argument ./etc. which is a directory rather than a file: /export/home/dandrear/Winter_2014_Solutions>./srchfile.sh then /etc error: second argument must be a file usage: ./srchfile.sh search-pattern file Part 2 Description: Write a shell script named, srch.sh. The srch.sh script will call the srchfile.sh script to perform a specific task. and accept two command line arguments. The first argument shall be a string (pattern) found in the file being searched. The second command line argument shall be the name of a file or a directory. Requirements: . The second argument represents either the name of the file to be searched or a directory. If a directory is entered, then all files in the directory shall be searched. . The script .srch.sh. shall use the script .srchfile.sh. to search for the string in a given file. If the second argument is a directory, then .srch.sh. will invoke .srchfile.sh. repeatedly in a loop. . If the user enters more or less than the required number of arguments, the script shall produce an error message and stop. . The script must be able to execute on the cs.franklin.edu machine . The script file name must be: .srchfile.sh.. . Both scripts must be located in $HOME/itec400/homework directory . The itec400 and homework directory permissions should be 705 . The script permissions should be 705 Sample Output: Sunny Day scenario, the srch.sh script searching for string .child. in the file zombie.c: /export/home/dandrear/Winter_2014_Solutions>./srch.sh child zombie.c ------ File = /export/home/dandrear/Winter_2014_Solutions/zombie.c ------ 13: pid_t child_pid; 15: child_pid = fork (); 16: if (child_pid > 0) { Rainy Day scenario, script srch.sh is invoked with only one command line argument: /export/home/dandrear/Winter_2014_Solutions>./srch.sh while error: must provide 2 arguments usage: ./srch.sh search-pattern file Rainy Day scenario, script srch.sh is invoked with three command line arguments: /export/home/dandrear/Winter_2014_Solutions>./srch.sh then printnum.sh xyz.sh error: must provide 2 arguments usage: ./srch.sh search-pattern file 

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

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

2. How can competencies be used in employee development?

Answered: 1 week ago