Question

Hello, please help with the following, you're tasked with writing a shell script named “rpsm.sh”....

Hello, please help with the following, you're tasked with writing 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 <options>< 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/anyuser/CYBR/files

4          /home/anyuser/CYBR/files/Perms

8          /home/anyuser/CYBR/files/EnvDemo

12        /home/anyuser/CYBR/files/BigFiles

24        /home/anyuser/CYBR/files/SomeSetgids

24        /home/anyuser/CYBR/files/SomeSetuids

76        /home/anyuser/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. Here’s 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

<more…>

You’ll 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 ~”.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the following script to find the output for given options.

Note: I have added some headers for the output to get more clarity when we use -a option

Script:

version=1.0
displayUsage()
{
echo "Usage: ./rpsm.sh <options>< directory>"
echo "Reports selected information about specified directory tree."
echo ""
echo "Options:"
echo "-h Print this help message."
echo "-v Print script version information, i.e., 1.0"
echo "-u Find and list all files (just file names) with setuid set, all owners"
echo "-g Find and list all files (just file names) with setgid set, all owners"
echo "-w Find and list all files (just file names) that are world-writable"
echo "-b Find and list all files (just file names) whose size is at least 10M"
echo "-d Report directory disk usage"
echo "-i Report information about the file system"
echo "-a All of the above (except -h and -v)"
echo ""
}

option_u()
{
   echo "list all files (just file names) with setuid set, all owners"
   find $1 -type f -perm +4000
   echo ""
}
option_g()
{
   echo "list all files (just file names) with setgid set, all owners"
   find $1 -type f -perm +2000
   echo ""
}
option_w()
{
echo "list all files (just file names) that are world-writable"
find $1 -type f -perm -o+w
   echo ""
}
option_b()
{
   echo "list all files (just file names) whose size is at least 10M"
   find $1 -type f -size +10485759
   echo ""
}
option_d()
{
echo "Report directory disk usage"
du $1
   echo ""
}

option_i()
{
   echo "Report information about the file system"
   df $1
   echo ""
}

option_a()
{
option_u $1
option_g $1
option_w $1
option_b $1
option_d $1
option_i $1

   echo ""
}
if [ $# -eq 1 ]
then
if [ "$1" == "-h" ]
then
     echo "Usage: ./rpsm.sh … … (except -h and -v)"
     exit
elif [ $1 == "-v" ]
then
     echo $version
     exit
else
     displayUsage
     exit
fi
fi

if [ $# -lt 2 ]
then
   displayUsage
   exit
fi

arg=${@:$#}

avalue=$arg

while getopts 'hvugwbdia:' OPTION; do
case "$OPTION" in
    h)
      displayUsage
      exit
      ;;

    v)
      echo $version
      exit
      ;;

    u)
      option_u $avalue
      ;;
    g)
      option_g $avalue

      ;;
    w)
      option_w $avalue
      ;;
    b)
      option_b $avalue

      ;;
    d)
      option_d $avalue

      ;;
    i)
      option_i $avalue

      ;;
    a)
      option_a $avalue

      ;;
    ?)
      displayUsage
      exit 1
      ;;
esac
done
shift "$(($OPTIND -1))"

Output:

User1> ./rpsm.sh -a
Usage: ./rpsm.sh <options>< directory>
Reports selected information about specified directory tree.

Options:
-h Print this help message.
-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)

User1> ./rpsm.sh -a .
list all files (just file names) with setuid set, all owners
./log

list all files (just file names) with setgid set, all owners
./log

list all files (just file names) that are world-writable
./sleep_kill.sh

list all files (just file names) whose size is at least 10M

Report directory disk usage
43252   .

Report information about the file system
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sb2       94882804 70061400 24821404 74% /disk/wsg


User1> ./rpsm.sh -di /users/gop/
Report directory disk usage
402932 /users/gop/

Report information about the file system
Filesystem            1K-blocks       Used Available Use% Mounted on
sw.americusa.net:/disk/data/users/gop
                     2113655744 1980220160 111960768 95% /users/gop

User1>./rpsm.sh -h
Usage: ./rpsm.sh … … (except -h and -v)
User1>./rpsm.sh -v
1.0
User1>./rpsm.sh -di .
Report directory disk usage
43252   .

Report information about the file system
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sb2       94882804 70061400 24821404 74% /disk/wsg

User1>./rpsm.sh -id .
Report information about the file system
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sb2       94882804 70061400 24821404 74% /disk/wsg

Report directory disk usage
43252   .

User1>./rpsm.sh -a .
list all files (just file names) with setuid set, all owners
./log

list all files (just file names) with setgid set, all owners
./log

list all files (just file names) that are world-writable
./sleep_kill.sh

list all files (just file names) whose size is at least 10M

Report directory disk usage
43252   .

Report information about the file system
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sdb2       94882804 70061400 24821404 74% /disk/wsg


Add a comment
Know the answer?
Add Answer to:
Hello, please help with the following, you're tasked with writing a shell script named “rpsm.sh”....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Objective : Write a C Shell script which copies all files(*.java and *.class) from your home dire...

    Objective : Write a C Shell script which copies all files(*.java and *.class) from your home directory to a new one, and Analyze the new directory information such as number of files, user permissions, and disk usage. Sample Output:                                                    << CS Directory Analysis >>      Date:   ============================================================ Current Directory: /home/tomss New Directory Created : /home/tomss/pgm01 File information Total Number of files : 22 files Directory files:   0 files Plain text files:   10 files File have read permissions: 3 files File have...

  • Write a script named listEmptyDir.sh that will do the following: (a) take a name of a...

    Write a script named listEmptyDir.sh that will do the following: (a) take a name of a directory as a parameter; (b) loop through all files in this directory and display their names; (c) if a file is a directory and has no files in it (empty directory), add the name of this empty directory to the file EmptyDir.txt in your current directory. If the number of parameters is not 1 or a parameter is not a directory, display the “usage”...

  • I need help with this. 22. Show a command that will create a file named "etc.tar"...

    I need help with this. 22. Show a command that will create a file named "etc.tar" in your home directory from recursively going through all of the files in the "/etc" directory. In other words, the "etc.tar" file will include the files in the "/etc" directory as well as all of its subdirectories. IMPORTANT: This command must work for any user as well as work from any directory. 23. In bash, multiple commands can appear on a single command line...

  • If possible, please answer all 4 questions. Thanks! :) 24. What command can be used to...

    If possible, please answer all 4 questions. Thanks! :) 24. What command can be used to show disk usage by file system? a. du b. df c. mount d. repquota 26. What command can you use to modify the grace period for quota soft limits? 27. What command would you use to check a ReiserFS file system for errors? a. fsckreiser b. reiserfsck c. reiserfs -check d. reiserfs --check 28. You cannot unmount a filesystem that you had previously mounted...

  • using lubuntu ce the following activities on your Linux virtual machine. Then complete estions. Write a script file which when executed will perform the following: First display today's date in d...

    using lubuntu ce the following activities on your Linux virtual machine. Then complete estions. Write a script file which when executed will perform the following: First display today's date in dd.mm.YYYY format (e.g. 20.04.2019). Ask user to enter a name to create a directory. Create a directory by the given directory name above. . . Ask user to enter a name to create a file. Copy the file /etc/passwd to the given filename above inside the newly created directory Copy...

  • Revision Question 3 on Linux. Please explain the shell script commands in the context of post...

    Revision Question 3 on Linux. Please explain the shell script commands in the context of post execution. You have just logged in and have a directory called "novel" in your home directory containing the following files: chapter1.docx chapter2.docx chapter3.docx draft.pdf save where "save" is itself a directory and contains the files Attributes.txt draft.pdf.1 draft.pdf.2 draft.pdf.3 indexA.txt indexB.txt list1.txt list2.txt a) Describe the results you would expect when executing the following shell commands: i) ls novel/save/*A* ii) ls novel/*r[23]* iii) rmdir...

  • (In Linux) 1. Create a file to write to from your script and save it as...

    (In Linux) 1. Create a file to write to from your script and save it as “.txt”. 2. Write the following information to the file that you created in Step 1: Today's date Your full name Your student ID The name of your course What directory you are in File permissions of the file that you created that allow everyone to read, write, and execute The long list of files in your current directory, providing all items and their process...

  • Unix questions, i need help on Hint: Commands to study to answer this question: predefined shell...

    Unix questions, i need help on Hint: Commands to study to answer this question: predefined shell variables, and .profile script file, echo SHELL, HOME, PATH, MAIL and TERM are predefined shell variables. You can use the value of a shell variable in a shell command putting $ in front of it. For example, to display the value of the HOME directory of the user, specify $HOME in the echo command like echo $HOME. Do not give just the value of...

  • SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5...

    SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5 input arguments in a for loop, but only add the even i values to sum and display the result. Problem 6: Write a shell script that accepts path of the directory and returns a count of all the files within the specified directory. (Hint: use alias to perform cd operation) Problem 7: Write a shell script that takes an ‘count’ value as an input...

  • LUNIX (Please Label) Exit vi (:q) and from the command line, type viscript4.sh. For this script,...

    LUNIX (Please Label) Exit vi (:q) and from the command line, type viscript4.sh. For this script, we will iterate through all files in the current directory print out their name using the for loop. Example (do not type yet): foriin*;do …;done where the…does some operation on$I, which stands for the current file. To do this, enter the following in your script4.sh file:           #!/bin/bash           for i in *; do                echo $i           done Once the above works, change the for loop to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT