What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Bash script to get free space for a specific mount point

Votes:

9

Hi,

Here is a script we wrote to check free space on a mount point passed in parameter. If the mount point is nfs type, the script writes and deletes a test file to validate the access.

The free space percentage is recalculated since the df command output.

Thank's for your returns.

Matthieu

#!/bin/bash
#
# This script return df result for the mount point
# and check if writing on it is possible (NFS only)
# support: [email protected]

if [ $# != 1 ]
  then
    echo "<prtg>"
        echo "   <error>1</error>
   <text>Please specify a mount point</text>"
        echo "</prtg>"
  exit 1
fi


# Data collecting
data=($(df -PkTm | grep -w $1 | awk '{ print $2,$3,$4,$5,$6 }'))

# Compute real free percent space
freep=$(awk "BEGIN { pc=100*${data[3]}/${data[1]}; i=int(pc); print (pc-i<0.5)?i:i+1 }")

# Check NFS writing
if [ "${data[0]}" = "nfs" ]; then
	touch "$1/test"
	if [ $? -ne 0 ]; then
	    echo "<prtg>"
            echo "   <error>1</error>
   	<text>Unable to write on $1</text>"
            echo "</prtg>"
	else
	   rm -f "$1/test"
	fi
fi

# Output

echo "<prtg>"

echo "<result>
<channel>Free%</channel>
<value>$freep</value>
<Unit>Percent</Unit>
<LimitMinWarning>12</LimitMinWarning>
<LimitMinError>10</LimitMinError>
<LimitMode>1</LimitMode>
</result>"

echo "<result>
<channel>Total</channel>
<value>${data[1]}</value>
<CustomUnit>MBytes</CustomUnit>
</result>"

echo "<result>
<channel>Used</channel>
<value>${data[2]}</value>
<CustomUnit>MBytes</CustomUnit>
</result>"

echo "<result>
<channel>Free</channel>
<value>${data[3]}</value>
<CustomUnit>MBytes</CustomUnit>
</result>"

echo "</prtg>"




exit 0

bash-script custom-script-exe free-disk-space linux nfs prtg ssh-script-advanced-sensor unix

Created on Mar 3, 2016 11:01:35 PM

Last change on Oct 12, 2017 3:21:01 PM by  Martina Wittmann [Paessler Support]



1 Reply

Accepted Answer

Votes:

0

Thank you very much for sharing this script, Matthieu! Awesome!

Just in case other users wonder how to use the script for monitoring with PRTG, they are welcome to follow these steps:

  1. Copy the script code and store it in the /var/prtg/scriptsxml directory on the Linux/Unix machine that you want to monitor. Name your file, for example, CustomMountPointFreeSpace.sh
  2. In PRTG, add the SSH Script Advanced sensor to the target Linux/Unix device.
  3. In the Add Sensor dialog, provide your Script. Select the CustomMountPointFreeSpace.sh (or correspondingly named) file from the list.
  4. Continue to create your sensor and enjoy monitoring the free space of your mount point!

Created on Mar 4, 2016 9:12:29 AM by  Torsten Lindner [Paessler Support]

Last change on Oct 12, 2017 3:20:09 PM by  Martina Wittmann [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.