Question: You are asked to write a shell script named rpsm.sh. The script reports and prints (to stdout) selected storage management information. Think of it as

You are asked to write a shell script named rpsm.sh. The script reports and prints (to stdout) selected storage management information. Think of it as RePort Storage Management.

The easy way to describe what the script needs to do is to look at what it should display in the case where you provide incorrect parameters, or in the case where you provide -h for help:

Usage: ./rpsm.sh < directory>

Reports selected information about specified directory tree.

Options:

-h Print this help message, i.e., Usage: ./rpsm.sh (except -h and -v)

-v Print script version information, i.e., 1.0

-u Find and list all files (just file names) with setuid set, all owners

-g Find and list all files (just file names) with setgid set, all owners

-w Find and list all files (just file names) that are world-writable

-b Find and list all files (just file names) whose size is at least 10M

-d Report directory disk usage

-i Report information about the file system

-a All of the above (except -h and -v)

There are files which match these criteria on the machine loki.ist.school.edu in the directory /home/user/CYBR. It might be easier to test your script against this directory instead of / for example because it will be much faster and you will not get a bunch of permission denied messages.

Grading rubrics:

Most of the options above are self-explanatory, but some are not, so let me provide examples for the latter case. The -d option should produce sorted output just like (may be more, not exactly the same as) the following. Hint: look at du command. Pay attention to the calculation in the last line regarding the total usage: 76 = 4+8+12+24+24 (we just need to consider all directories listed here).

user@loki:~$ ./rpsm.sh -d /home/user/CYBR/files

4 /home/user/CYBR/files/Perms

8 /home/user/CYBR/files/EnvDemo

12 /home/user/CYBR/files/BigFiles

24 /home/user/CYBR/files/SomeSetgids

24 /home/user/CYBR/files/SomeSetuids

76 /home/user/CYBR/files

The -i option shows me information about the file system holding the directory I am asking about. (Hint: look at the df command.) It does not give me all of the information but it should look just like the following. You control the spaces or tabs between two columns, but should make it read clearly.

user@loki:~$ ./rpsm.sh -i /home/ user/CYBR

Filesystem Type Use% Mounted on

prog.ist.school.edu:/home nfs4 52% /home

Again, you will want to figure out how to get the information and then also how to cut it up. Heres another example regarding the combination of two options -i and then -d:

user@loki:~$ ./rpsm.sh -id /etc

Filesystem Type Use% Mounted on

/dev/mapper/loki-root ext4 28% /

4 /etc/apache2/sites-enabled

4 /etc/apparmor.d/disable

4 /etc/apparmor.d/force-complain

4 /etc/apparmor.d/tunables/multiarch.d

4 /etc/apparmor/init/network-interface-security

Youll note that the output for -id versus -di would be different because of the order of the command line arguments. Also note that you need to handle -, for instance -id as the same as -i -d. We have already covered getopts in this class - use it!

And ./rpsm.sh -i -d ~ is equivalent to ./rpsm.sh -id ~, ./rpsm.sh -d -i ~ is equivalent to ./rpsm.sh -di ~.

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!