Question: Using Ubuntu, this is the script to use: #!/bin/bash CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g') THRESHOLD=$1 # if

Using Ubuntu, this is the script to use:

#!/bin/bash

CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')

THRESHOLD=”$1”

#

if [ "$CURRENT" -gt "$THRESHOLD" ] ; then

echo “WARNING-Root partition space low Used: $CURRENT%“ >> ~/systemlog

fi

Using an editor enter the script and name it script1

Make script1 an executable file:

$ chmod +x /~/script1

Now run script1 by passing in a 90, representing 90%, as the parameter.

$ cd ~

$ ./script1 90

Test to make sure your if statement works properly by passing in a 10 as the parameter.

$ ./script2

$ ./script1 10

$ ./script2

$ cat /~/systemlog

  1. Now that you are becoming familiar with bash scripting enhance script 1 to do these items:
  • Require the script to now use (2) parameters that are passed in.
  • Check for the number of parameters passed in and if it is not 2, display an error message and exit.
  • The second parameter will represent a value for the minimum amount of available memory (IE: 200000).
  • Parse the output from the vmstat or free command for the amount of free memory. Let’s call this the free_value. Compare free_value to the value passed in for parameter 2. If free_value is less than parameter 2 issue a warning message that will be written to ~/systemlog.

Test to make sure your script3 works properly by passing these test case parameters:

$ ./script3

$ ./script3 10

$ ./script3 10 800000

$ ./script3 90 200000

$ ./script3 90 800000

$ cat /~/systemlog

I need the script with the parameters and below. I have script1 working, it's just the last half that I don't have.


Step by Step Solution

3.41 Rating (148 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Code binbash if ne 2 then echo illegal number of parameters exit 1 fi CURRENTdf g... View full answer

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 Finance Questions!