Simple shell-script doesnt work

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
porkenza
Posts: 3
Joined: Tue Aug 30, 2011 1:26 am

Simple shell-script doesnt work

Post by porkenza »

Hello all,

i have a simple shell-script, when i run the script as user cacti direct from the command line it works, but not when the poller runs the script.

Script:
FILE="/tmp/proxy"
proxy21=$(cat ${FILE} | /usr/bin/grep "10.x.x.x" | /usr/bin/grep "Masq" | /usr/bin/awk 'BEGIN {FS=" "} {print $5}'|tr -d '\012')
proxy22=$(cat ${FILE} | /usr/bin/grep "10.x.x.x" | /usr/bin/grep "Masq" | /usr/bin/awk 'BEGIN {FS=" "} {print $5}'|tr -d '\012')
proxy23=$(cat ${FILE} | /usr/bin/grep "10.x.x.x" | /usr/bin/grep "Masq" | /usr/bin/awk 'BEGIN {FS=" "} {print $5}'|tr -d '\012')
/usr/bin/printf "proxy21:%s proxy22:%s proxy23:%s" ${proxy21} ${proxy22} ${proxy23}

Output (Commandline) as user cacti:
proxy21:207 proxy22:217 proxy23:215

Output cacti log:
output: proxy21: proxy22: proxy23:

I can't find my mistake, can someone assist?

Thanks in advance

regards,

Porkenza
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: Simple shell-script doesnt work

Post by noname »

Try to specify "cat" and "tr" with absolute pathname.
porkenza
Posts: 3
Joined: Tue Aug 30, 2011 1:26 am

Re: Simple shell-script doesnt work

Post by porkenza »

Same result, no data in cacti.
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: Simple shell-script doesnt work

Post by noname »

Then, try to investigate the results when your script was performed from cron, as like this.
porkenza
Posts: 3
Joined: Tue Aug 30, 2011 1:26 am

Re: Simple shell-script doesnt work

Post by porkenza »

ok, i had to add the following line to the script, then it works under cron:

#!/bin/bash
. /home/cacti/.profile
proxy21=$(/bin/cat /tmp/proxy | /usr/bin/grep "10.3.81.21" | /usr/bin/grep "Masq" | /usr/bin/awk 'BEGIN {FS=" "} {print $5}'|/usr/bin/tr -d '\012')
proxy22=$(/bin/cat /tmp/proxy | /usr/bin/grep "10.3.81.22" | /usr/bin/grep "Masq" | /usr/bin/awk 'BEGIN {FS=" "} {print $5}'|/usr/bin/tr -d '\012')
proxy23=$(/bin/cat /tmp/proxy | /usr/bin/grep "10.3.81.23" | /usr/bin/grep "Masq" | /usr/bin/awk 'BEGIN {FS=" "} {print $5}'|/usr/bin/tr -d '\012')
/usr/bin/printf "proxy21:%s proxy22:%s proxy23:%s" ${proxy21} ${proxy22} ${proxy23}

But the same result in the cacti log, no data.
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: Simple shell-script doesnt work

Post by noname »

Then, try:
1) System Utilities -> Rebuild Poller Cache
2) Delete the RRD file or/and Re-create the datasource (and graph)
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests