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

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

Votes:

0

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



1 Reply

Accepted Answer

Votes:

5

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.

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

$(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:

test.sh

#!/bin/bash

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

source "$my_dir/includes/functions.sh"

VAL1="TEST1"
VAL2="TEST2"
OUTPUT=$(print_xml ${VAL1} ${VAL2})

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

functions.sh (in "includes" folder)

function print_xml() {

xmlresult=`cat << EOF
  <result>
    <channel>$1</channel>
    <value>$2</value>
  </result>
EOF
`
echo $xmlresult

Structur:

  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“ ;).

Best

Sascha

Created on Dec 29, 2014 3:12:33 PM

Last change on Dec 29, 2014 3:45:29 PM by  Torsten Lindner [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.