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.
300.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

error bash ssh script

Votes:

0

Your Vote:

Up

Down

i have a problem with ssh script and ssh advanced script the connection return me a strange simbol and the ssh advanced go in error for junk after </prtg> the junk is [1]+ Done(127) [email protected]

this is the log

[INFO][3/11/2021 4:36:07 PM] Opening Connection
[INFO][3/11/2021 4:36:07 PM] Shell: $SHELL = /bin/bash
 72567 pts/1    00:00:00 sh
[1]+  Done(127)               [email protected]v

[INFO][3/11/2021 4:36:07 PM] Sending command /var/prtg/scriptsxml/check_cpu.sh 
[INFO][3/11/2021 4:36:08 PM] Sending EOF
[INFO][3/11/2021 4:36:08 PM] Reading PaeSSH result
[INFO][3/11/2021 4:36:08 PM] [STDOUT] <?xml version="1.0" encoding="UTF-8" ?>
<prtg>
   <result>
       <channel>%usr</channel>
         <value> <Unit> CPU </Unit> <float>
 all </float></value>
   </result>
   <result>
       <channel>%nice</channel>
         <value> <Unit> CPU </Unit> <float>
0.79 </float></value>
   </result>
   <result>
       <channel>%sys</channel>
         <value> <Unit> CPU </Unit> <float>
 0.00 </float></value>
   </result>
<result>
       <channel>%iowait</channel>
         <value> <Unit> CPU </Unit> <float>
 0.16 </float></value>
   </result>
<result>
       <channel>%irq</channel>
         <value> <Unit> CPU </Unit> <float>
 0.02  </float></value>
   </result>
<result>
       <channel>%soft</channel>
         <value> <Unit> CPU </Unit> <float>
 0.00  </float></value>
   </result>
<result>
       <channel>%steal</channel>
         <value> <Unit> CPU </Unit> <float>
 0.02  </float></value>
   </result>
<result>
<channel>%guest</channel>
         <value> <Unit> CPU </Unit> <float>
 0.02 </float></value>
   </result>
<result>
<channel>%gnice</channel>
         <value> <Unit> CPU </Unit> <float>
 0.00  </float></value>
   </result>
<result>
<channel>%idle</channel>
         <value> <Unit> CPU </Unit> <float>
0.00  </float></value>
   </result>
</prtg>
[1]+  Done(127)               [email protected]

[INFO][3/11/2021 4:36:08 PM] [STDERR] 
[INFO][3/11/2021 4:36:08 PM] Sending exit
[INFO][3/11/2021 4:36:08 PM] Sending EOF

of course if i lunch the scritp on the vm the result is correct i have the last version 21.1.66.1623+

ssh ssh-script ssh-script-advanced-sensor

Created on Mar 11, 2021 4:44:15 PM by  michelescapiniclz (0) 2

Last change on Mar 11, 2021 5:19:16 PM by  Felix Wiesneth [Paessler Support]



10 Replies

Votes:

0

Your Vote:

Up

Down

ok, now is ok. i was in error, i selected use sudo with password but is correct in my enviroment to use sudo without sudo. Now i have all data but in integer

Created on Mar 12, 2021 9:46:52 AM by  michelescapiniclz (0) 2



Votes:

0

Your Vote:

Up

Down

Hello Michele,

Thank you for your messages.

According to the screenshots you provided, the structure of the response returned to PRTG is incorrect.

The response should follow the structure as illustrated below, as indicated in our manual right here: https://www.paessler.com/manuals/prtg/custom_sensors#advanced_sensors

<?xml version="1.0" encoding="UTF-8" ?>
<prtg>
<result>
<channel>NAME</channel>
<value>VALUE</value>
<Unit> CPU </Unit>
<float> 1 </float>
</result>
</prtg>

NAME and VALUE must be replaced with the information you want.

Regards.

Created on Mar 12, 2021 10:47:32 AM by  Florian Lesage [Paessler Support]



Votes:

0

Your Vote:

Up

Down

ok thanks a lot. Now i have corrected the error but the data are incorrect

Created on Mar 12, 2021 10:53:33 AM by  michelescapiniclz (0) 2



Votes:

0

Your Vote:

Up

Down

Thank you for your feedback.

Can you please create the sensor anew (do not duplicate it) and check if the values are correct afterwards.

Regards.

Created on Mar 12, 2021 2:49:49 PM by  Florian Lesage [Paessler Support]



Votes:

0

Your Vote:

Up

Down

yes, i have recreated. it seems the cut not work fine in script launched by prtg but is fine in ssh session. here the script

#!/bin/sh
cpu="$(mpstat 1 1 | sed -n '4p')"
#$cpu | cut -d ' ' -f

echo -n "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<prtg>
<result>
<channel>%usr</channel>
<value>"
usr=$(echo $cpu | cut -d " " -f 4)
echo -n "$usr</value>
<unit> percent </unit>
<float> 1 </float>
</result>
<result>
<channel>%nice</channel>
<value>"
nice=$(echo $cpu | cut -d " " -f 5)
echo -n "$nice</value>
<Unit> percent </Unit>
<float> 1 </float>
</result>
<result>
<channel>%sys</channel>
<value>"
sys=$(echo $cpu | cut -d " " -f 6)
echo -n "$sys</value>
<Unit>percent</Unit>
<float>1</float>
</result>
<result>
<channel>%iowait</channel>
<value>"
iowait=$(echo $cpu | cut -d " " -f 7)
echo -n "$iowait</value>
<Unit>percent</Unit>
<float>1</float>
</result>
<result>
<channel>%irq</channel>
<value>"
irq=$(echo $cpu | cut -d " " -f 8)
echo -n "$irq</value>
<Unit>percent</Unit>
<float>1</float>
</result>
<result>
<channel>%soft</channel>
<value>"
soft=$(echo $cpu | cut -d " " -f 9)
echo -n "$soft</value>
<Unit>percent</Unit>
<float>1</float>
</result>
<result>
<channel>%steal</channel>
<value>"
steal=$(echo $cpu | cut -d " " -f 10)
echo -n "$steal</value>
<Unit>percent</Unit>
<float>1</float>
</result>
<result>
<channel>%guest</channel>
<value>"
guest=$(echo $cpu | cut -d " " -f 11)
echo -n "$guest</value>
<Unit>percent</Unit>
<float>1</float>
</result>
<result>
<channel>%gnice</channel>
<value>"
gnice=$(echo $cpu | cut -d " " -f 12)
echo -n "$gnice</value>
<Unit>percent</Unit>
<float>1</float>
</result>
<result>
<channel>%idle</channel>
<value>"
idle=$(echo $cpu | cut -d " " -f 13)
echo "$idle</value>
<Unit>percent</Unit>
<float>1</float>
</result>
</prtg>"

here the screenshot of command
so if i use echo $cpu | cut -d " " -f 3 in ssh session i get 0.38 throught prtg sensor (i used save result) i get all. so i've increased all by 1 and seems fine

Created on Mar 12, 2021 2:54:50 PM by  michelescapiniclz (0) 2

Last change on Mar 12, 2021 4:26:23 PM by  Felix Wiesneth [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi,

Thank you for the update, is the SSH Script Advanced sensor working properly since the modification you made?

Regards.

Created on Mar 15, 2021 8:16:51 AM by  Florian Lesage [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Yes it's running fine. I don't understand why i have to increase the field of cut throught prtg script

Created on Mar 15, 2021 11:16:03 AM by  michelescapiniclz (0) 2



Votes:

0

Your Vote:

Up

Down

That behavior is effectively not expected, however it seems to be limited to the script you provided. We will have a look to the SSH sensor however as the issue is solved it has a low priority.

To avoid such issue, I would recommend to use a loop here to generate the JSON as well as execute the cut command only once and store its values inside a list.

Regards.

Created on Mar 15, 2021 1:35:58 PM by  Florian Lesage [Paessler Support]



Votes:

0

Your Vote:

Up

Down

ok, so with json i could use a list without cut? how can i do this?

Created on Mar 15, 2021 3:21:28 PM by  michelescapiniclz (0) 2



Votes:

0

Your Vote:

Up

Down

Hello,

You need to use the command cut to create a list in which the CPU values will be stored. You will need an other list with the channels name on which the script can loop to dynamically generate the JSON (<result>...</result>).

Here is a structure which could be used:

  • Create list of channels name
  • Create list of CPU values
  • open response structure with echo -n "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
  • Use loop to generate each channel with <result>...</result>
  • Close the response with </prtg>

Here is a website which explains how to use list in bash: https://linuxconfig.org/how-to-use-arrays-in-bash-script

Please, notice that we do not provide support for custom scripts, therefore I can only provide the indications mentioned above.

Regards.

Created on Mar 16, 2021 6:41:02 AM by  Florian Lesage [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.