Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!