Assignment #4 Basic Shell scripting with control structures.ZIP

Assignment #4 Basic Shell scripting with control structures


Objective
To practice with shell scripting, and learn the basic skills to write shell scripts that
perform simple tasks involving the monitoring of directories and files.
Task
A given UNIX directory may contain many files and subdirectories. For the purpose of this assignment, a "file" is a non-directory file, and a directory is a subdirectory of the given directory. Each file or directory might have different permissions. For example, a file might have read and execute permissions for the owner. A directory might have only read permission.
In this assignment, you will write a shell script that calculates the following information for the contents of a given directory. The directory that you will analyze will be passed in as a single command line argument to your script. You don’t need to account for any contents of nested subdirectories -- just the direct contents of the specified directory passed in as a directory.
1. The total number of directories that are in directory passed as a parameter.
2. The total number of files in the given passed directory.
3. The number of items (files/directories) in the directory (passed as a parameter)
that are readable.
4. The number of items (files/directories) in the directory (passed as a parameter)
that are writable.
5. The number of items (files/directories) in the directory(passed as a parameter) that are executable.
Note that any hidden files or hidden directories are not included in this count. For
example, ".."_ represents the parent directory of the current directory and is not counted as a directory or as a file. Similarly, ".login"_ would not be counted. Only regular files and directories in the given directory are calculated.
Requirements
• The script should be named assignment6.sh
• The script must be written to run under the bash shell!
• Your script must check for the correct number of arguments (one argument). If
somebody tries to invoke the script without passing in the correct number of
arguments, then output this usage message and abort the script:
Usage: assignment6.sh <directory_name
• Your script must also check that the command line argument actually exists and is a valid directory (any directory). If it is not, then output an appropriate error message, and end the script processing. Example: If the user inputs a parameter
that is not a directory you should issue the following message:
assignment6.sh abcd
abcd: No such directory
• The script should print all of its results to standard output
• Include comments at the top of your script file, which specify your name, the course (COP 3353), the assignment number, and the date
Sample Runs
Gaitros: assignment6.sh
Usage: assignment6.sh <directory
Gaitros: assignment6.sh ABCD
ABCD: no such directory
Gaitros: assignment6.sh tempdir
Statistics on the directory tempdir
Number of Directories: 1
Number of Files: 15
Number of Readable files: 13
Number of Writeable files: 13
Number of Executable Files: 15
Gaitros:assignment6.sh ~gaitrosd
Statistics on the directory /home/faculty/gaitrosd
Number of Directories: 1
Number of Files: 174
Number of Readable files: 174
Number of Writeable files: 174
Number of Executable Files: 157
Submitting
Submission
Go to the Blackboard site (campus.fsu.edu) and login to your account and access the COP3353 portal. Select Assignments and select Assignment6. Follow the directions for submitting an assignment on Blackboard. You need to submit the file assignment6.sh
for this assignment. You can make up to 5 submissions and the last submission will be graded.
Powered by