What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

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

[How-To] Use more than one shell file in EXE/XML



Your Vote:



I want to use a functions shell class in all of my EXE/XML scripts. Some functions are returning and maybe it is useful to handle events or „pushes“ to another shell file, beside PRTG.

Maybe a reset of an value in a database or something like that. Otherwise it is possible to declare the PRTG XML structure.

With a function you can access this structure via function name.

exe-xml functions multi-file shell

Created on Dec 29, 2014 2:45:10 PM by  Sascha Lewandowski (2,291) 3 4

1 Reply

Accepted Answer



Your Vote:



To write an EXE/XML sensor shell script with a functions class in the same folder or another is easy, but also a bit tricky. PRTG started the scripts not in default „root“ in shell. PRTG launches the shell scripts in "/var/prtg/scripts" & "/var/prtg/scriptsxml". So we have to tell the script, that it is in a shell.

my_dir="$(dirname "$0")"
source "$my_dir/includes/functions.sh"

$(dirname „$0“) is a global function for the Folder where the shell file is executed. You can call it "absolute path", similar to (`pwd` /$0). Now we can link a new file via „source“ to the first one and this will work correctly.

We are able to activate a „functions“ class in an external shell file and include it into the main part of the sensor file.

Example script:



my_dir="$(dirname "$0")"

source "$my_dir/includes/functions.sh"

OUTPUT=$(print_xml ${VAL1} ${VAL2})

echo "<prtg>"
echo $OUTPUT
echo "</prtg>"

functions.sh (in "includes" folder)

function print_xml() {

xmlresult=`cat << EOF
echo $xmlresult


  1. test.sh
  2. includes/
    1. functions.sh

This is an example to write an template for creating the xml code inside PRTG XML sensor list.

This will make your script a bit „slender“ ;).



Created on Dec 29, 2014 3:12:33 PM by  Sascha Lewandowski (2,291) 3 4

Last change on Dec 29, 2014 3:45:29 PM by  Torsten Lindner [Paessler Support]

Please log in or register to enter your reply.

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.