Sale!

 Project 1 Bash scripts

$25.00

Category:

Description

5/5 - (3 votes)

Project 1
The purpose of this project is provide experience with developing bash scripts. Problem Statement UNIX users often complain that the rm command is too unforgiving. If they accidentally delete a file it is gone forever. We would like a new command sfrm (“safe remove”) that moves files to a trash directory. In addition, we would like a new command unsfrm (“undo safe remove”) that restores files from the trash directory, and a new command emptytrash that permanently removes files from the trash directory. Assignment (10 points) Write a bash shell script sfrm. The requirements for this command are: • sfrm will accept any number of arguments, but if there are no arguments, it should print out usage information and a short synopsis of what it does. • sfrm works only with ordinary files (i.e., not directories, symbolic links, etc.). For an argument that is not an ordinary file, an error message should be displayed, but otherwise the argument is ignored. • sfrm moves the ordinary file arguments to the trash directory $HOME/.trash. The shell script should create this directory if it does not already exist. • sfrm does not write over files with the same name. If there is already a file of the same name, sfrm should ask the user for another name. For example, assume that the trash directory contains a file named foo.txt and the user has a file named foo.txt in the directory bar. The following dialog would take place: $ sfrm bar/foo.txt Cannot move bar/foo.txt; foo.txt already exists in /home/user/.trash New name to store under: foo.bar $ The file bar/foo.txt would then be moved to $HOME/.trash/foo.bar instead of writing over the existing $HOME/.trash/foo.txt. Note that the user may enter a new name that also exists in the trash directory, so sfrm must check again to make sure that it is not writing over a file with the new name. It should continue asking until there is no conflict. • Note that in the example above, the user entered the name bar/foo.txt, but the program correctly checked for foo.txt in the trash directory. To strip off the leading directory names, you can use the basename command. (10 points) Write a bash shell script unsfrm. The requirements for this command are: • unsfrm will accept any number of arguments, but if there are no arguments, it should print out usage information. • If there are two or more arguments, the last argument optionally may be a directory. • If the last argument is not an existing directory, unsfrm tries to move each of the file arguments from the trash directory ($HOME/.trash) to the current working directory. • If the last argument is a directory, unsfrm tries to move the other given file arguments from the trash directory to the named directory. • If an argument file does not exist in the trash directory, unsfrm should print an error message and continue to the next argument. • If an argument exists in the trash directory, and a file of the same name also exists in the directory the argument file is being moved to, unsfrm should prompt the user for whether to overwrite the file. If
Page 1 of 2
the response begins with “y”, unsfrm should overwrite the existing file. Otherwise, unsfrm should skip the argument file and continue to the next argument. (5 points) Write a bash script emptytrash that deletes the contents of the trash directory ($HOME/.trash). This command should not delete the trash directory itself.
(5 points) Provide a test plan for your project. I.e., give a list of commands that will demonstrate the features of your new commands. Annotate this list with notes regarding what result is expected. The grade for this portion of the project will depend on how thorough the test plan is. Note that the test plan should cover all of the project requirements whether or not the project actually implements them. What to Submit Create a tarfile or a zipfile containing the following items: • Well-documented executable bash scripts named sfrm, unsfrm, and emptytrash. • The test plan for your project in a PDF document.