Docsity

Shell Script Programming Assignment 4 - COP3353, Fall 2008 - Prof. Wickus Nienaber, Assignments of Computer Science

Toggle sidebar
bg1
COP3353 – Fall 2008
Assignment 4
Experiencing Shell Script Programming
Due Tuesday November 4, 2008 (midnight)
Objective: The objective of this assignment is to learn the basic skills to write shell
scripts that perform simple tasks involving monitoring directories and files.
Problem Description: 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 may have
different permissions. For example, a file may have read and execute permissions for the
owner. A directory may have only read permission. In this assignment, you are asked to
write a shell script that calculates the following information for a given directory
specified as a command line argument (as a parameter) to your program
1. The total number of directories. Do NOT include any subdirectories of a
directory.
2. The total number of files. Do NOT include any files in subdirectories.
3. The number of files that are readable. Do NOT include any files in subdirectories.
4. The number of files that are writable. Do NOT include any files in subdirectories.
5. The number of files that are executable. Do NOT include any files in
subdirectories.
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
Your shell script must check the following:
1. The correct number of arguments. Your script must take exactly one argument
that is the given directory. You must handle error conditions. For example if Bob
Smith erroneously types: %Bob_Smith.sh, the output should be something like:
%Usage: Bob_Smith.sh <directory_name>
2. You must check to make sure that the given directory exists and it is a directory.
For example, if Bob Smith types: %Bob_Smith.sh abcd the output should be:
%abcd: No such directory
3. Your script should print information to the standard output.
1
pf2

Partial preview of the text

Download Shell Script Programming Assignment 4 - COP3353, Fall 2008 - Prof. Wickus Nienaber and more Assignments Computer Science in PDF only on Docsity!

COP3353 – Fall 2008 Assignment 4 Experiencing Shell Script Programming Due Tuesday November 4, 2008 (midnight) Objective: The objective of this assignment is to learn the basic skills to write shell scripts that perform simple tasks involving monitoring directories and files. Problem Description: A given UNIX directory may contain many files and subdirectories. For the purpose of this assignment, a “file” is a nondirectory file and a directory is a subdirectory of the given directory. Each file or directory may have different permissions. For example, a file may have read and execute permissions for the owner. A directory may have only read permission. In this assignment, you are asked to write a shell script that calculates the following information for a given directory specified as a command line argument (as a parameter) to your program

  1. The total number of directories. Do NOT include any subdirectories of a directory.
  2. The total number of files. Do NOT include any files in subdirectories.
  3. The number of files that are readable. Do NOT include any files in subdirectories.
  4. The number of files that are writable. Do NOT include any files in subdirectories.
  5. The number of files that are executable. Do NOT include any files in subdirectories. 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 Your shell script must check the following:
  6. The correct number of arguments. Your script must take exactly one argument that is the given directory. You must handle error conditions. For example if Bob Smith erroneously types: %Bob_Smith.sh, the output should be something like: %Usage: Bob_Smith.sh <directory_name>
  7. You must check to make sure that the given directory exists and it is a directory. For example, if Bob Smith types: %Bob_Smith.sh abcd the output should be: %abcd: No such directory
  8. Your script should print information to the standard output. 1

Testing Be sure to test your program thoroughly. To help you understand how the program should work, a sample solution ~nienaber/COP3344/a4.sh is on linprog.cs.fsu.edu. You are encouraged to experiment with his program and compare the output to your output. Once you log onto linprog.cs.fsu.edu, you can execute the script using the following command: ~nienaber/COP3353/a4.sh.x Submission You are required to name your shell script as yourfirstname_yourlastname.sh. For example, suppose there is a student called Bob Smith, the file name should be called Bob_Smith.sh. Submit your assignment at: http://ww2.cs.fsu.edu/~nienaber/teaching/COP3353/ You can submit as many times as you like before the deadline. Your script must contain the following as comments as the second and third lines of the file: Section: Name: Sample output: 10:06pm program1 > a4.sh Usage: a4.sh 10:06pm program1 > a4.sh ~ Total number of directories: 37 Total number of files: 67 Number of files that are readable: 67 Number of files that are writeable: 67 Number of files that are executable: 10 10:06pm program1 > a4.sh. Total number of directories: 1 Total number of files: 5 Number of files that are readable: 5 Number of files that are writeable: 5 Number of files that are executable: 5 10:06pm program1 > a4.sh a Total number of directories: 0 Total number of files: 23 Number of files that are readable: 23 Number of files that are writeable: 23 Number of files that are executable: 6 10:06pm program1 > 2