One command will chart, the other will not, why???

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
ToddWilson
Posts: 16
Joined: Thu Nov 17, 2016 1:49 pm

One command will chart, the other will not, why???

Post by ToddWilson »

I have a script, egress.sh that I am using to populate a graph. If I assign value to the variable Egress directly, the script produces output that Cacti can read and I get a value on a chart. If I use the actual grep command that I need to populate the variable from a file, Cacti will not produce output. Why? There are no errors generated in poller-error.log either way.

#! /bin/bash

# If hash tags are removed, this works...
#Egress=500
#echo "Egress":$Egress

# However, when reading in a value from the actual data source, this does not...
Egress=$(grep Egress /home/parallels/Documents/expect_output.txt | cut -d ':' -f 2)
Egress=${Egress%$'\r'}
echo "Egress":$Egress


Sample Output: When I assign the value of 500 to Egress and then echo, I get this for output and Cacti graphs the value of 500:
parallels@ubuntu:~$ /home/parallels/Documents/./egress.sh
Egress:500

When I let the script run and actually pull a value from the expect_output.txt file, process, and echo, sample output looks like this:
parallels@ubuntu:~/Documents$ /home/parallels/Documents/./egress.sh
Egress:69.62

I don't get it - why won't Cacti accept the value?
User avatar
phalek
Developer
Posts: 2838
Joined: Thu Jan 31, 2008 6:39 am
Location: Kressbronn, Germany
Contact:

Re: One command will chart, the other will not, why???

Post by phalek »

maybe because of the additional \r you've added ?

Code: Select all

Egress=500
echo "Egress":$Egress
vs

Code: Select all

Egress=${Egress%$'\r'}
echo "Egress":$Egress
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
ToddWilson
Posts: 16
Joined: Thu Nov 17, 2016 1:49 pm

Re: One command will chart, the other will not, why???

Post by ToddWilson »

Phalek,

Thanks for the reply, I modified code to match exactly...

#! /bin/bash

# Prints egress value for use by cacti.

# The directory paths will need to be updated in this script to reflect the actual paths on the installed
# computer. Replace each instance of /home/parallels/Documents/... with the appropriate path.

# This works...
#Egress=500
#echo "Egress":$Egress

# This does not...
Egress=$(grep Egress /home/parallels/Documents/expect_output.txt | cut -d ':' -f 2)
#Egress=${Egress%$'\r'}
echo "Egress":$Egress

I get this for output:
parallels@ubuntu:~/Documents$ /home/parallels/Documents/./egress.sh
Egress:52.29

Still no poller log entries and still no joy on my chart.

T.
Last edited by ToddWilson on Mon Nov 21, 2016 9:00 am, edited 1 time in total.
User avatar
phalek
Developer
Posts: 2838
Joined: Thu Jan 31, 2008 6:39 am
Location: Kressbronn, Germany
Contact:

Re: One command will chart, the other will not, why???

Post by phalek »

Ok,

In this case it may simply be a permissions error.

Where did you put this script into, and which permissions did you assign to it ?

Can you also provide a screenshot of the data input query/method ?
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
ToddWilson
Posts: 16
Joined: Thu Nov 17, 2016 1:49 pm

Re: One command will chart, the other will not, why???

Post by ToddWilson »

Phalek,

Script is located in /home/parallels/Documents/egress.sh

Permissions assigned were chmod 755

See attached for data input method.

I wonder about the permissions line of thought as the script executes either way, that is, when I directly assign the value, the script runs. When I have the script read in the value, it runs then as well. I'm not changing out script files, I'm simply modifying the same file.

Standby for upload of Data Input Method - and Thanks! for the help!
Attachments
datainputmethod.jpeg
datainputmethod.jpeg (260.41 KiB) Viewed 1234 times
ToddWilson
Posts: 16
Joined: Thu Nov 17, 2016 1:49 pm

Re: One command will chart, the other will not, why???

Post by ToddWilson »

The script is executing, it will produce output when the variable is assigned directly, just not when reading. I'm sure I've got some formatting screw up somewhere!
Attachments
dwchart.jpeg
dwchart.jpeg (145.6 KiB) Viewed 1233 times
ToddWilson
Posts: 16
Joined: Thu Nov 17, 2016 1:49 pm

Script Update

Post by ToddWilson »

I've been experimenting. This is my current code revision. As before, if I assign the value directly, I get a line on my cacti chart. If I allow the grep command to execute, I get nothing. I've got to tell you, this is really starting to bother me. I have output both methods to a .txt file and made sure that there are no hidden characters lurking at the end of the grep statement. I need this to work and have exhausted any ideas.

#! /bin/bash

# This works...
#X=100.7

# This does not...
X=$(grep Egress /home/parallels/Documents/expect_output.txt | cut -d ':' -f 2 | tr -d '\015')

echo "Egress":$X
ToddWilson
Posts: 16
Joined: Thu Nov 17, 2016 1:49 pm

Re: One command will chart, the other will not, why???

Post by ToddWilson »

Output from each command as saved to a text file and loaded into a hex editor. The first dataset, 45 through 0A is the output when I set the variable manually. The last dataset is the output when my grep command is executed.

45 67 72 65 73 73 3A 31 30 30 2E 37 0A 45 67 72 65 73 73 3A 33 38 2E 39 34 0A
ToddWilson
Posts: 16
Joined: Thu Nov 17, 2016 1:49 pm

Re: One command will chart, the other will not, why???

Post by ToddWilson »

The solution to the problem is found here: http://forums.cacti.net/viewtopic.php?f=2&t=56605
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests