Due Thursday 29 April 2004

CSCI 330 Spring 2004
Bourne Shell Assignment 100 Points

Write a Bourne shell script to be called cleaner that will search for a file based on a variety of criteria. When a file is found, prompt user for permission to delete.

Write the script to search by file name or by string found in file. Start search from current working directory.

Write the script to run as a looped process. Upon running, a menu appears and offers user the appropriate choices. Once a task has been selected and run, the menu will reapear. Terminate program via a menu selection.

Write the menu feature as a Bourne function which displays the user's choices, prompts user for input, checks the input for valid data, and either re-displays menu if bad or passes choice back to main program. You may use the return code feature to return selection or you may use exec to redirect standard output.

Write the script to take a -s command line option (for search). When this option is used, the program will not offer to delete. Rather, it will just display the location of the files of interest.

menu() 
{
    while invalid choice
    {
      display menu selection
      get choice
      test choice for valid value
    }

    return choice
}


choice = menu()

if choice is by filename
  Use find to search for all files of that name
  For each file found
    if only search
      just display
    else
      offer to delete.

if choice is by string in file
  Use find to search for only regular readable file.
  For each located files, use grep to check for string match
    if only search
      just display
    else
      offer to delete.

if choice is quit 
  quit

Use the case command structure to process the choice returned by the menu.

For both search by name and by string options, use find with the option to only report on regular files. In other words, skip over directories.

When searching for filename to delete, use find to locate the file. You may either use find's ability to execute a command on located file or use a separate command to perform an interactive delete. Remember that you have to also code for the -s option, so handling delete separately may make coding easier.

For the search for string match, use find in a for statement to generate the list of candidate files. Use the find options to select only regular files that are readable by user. See -type and -perm options. In body of for loop, use the file command and a grep on its output to further select only text or script files. (You can run file on several of your own files to see the output). Then depending on search or delete choice, either just display or ask user to confirm delete.