Re: RRDTOOL Update with script in string

[email protected] (Tony Mountifield) Fri, 15 Jan 2016 17:18:29 +0000 (UTC)
Newsgroups gmane.comp.db.rrdtool.user
Organization Software Insight Ltd., Winchester, UK
Message-ID <[email protected]>
In article <[email protected]>,
Simon Hobson <[email protected]> wrote:
> maxmax20 <[email protected]> wrote:
> 
> > rrdtool update /home/pi/net/net.rrd N:'cut -d, /home/pi/net/devices.csv -f13
> > | cut -d: -f2'::::: to get the first value out of the csv file, but it seems
> > that it won't work.
> 
> As suggested, put echo in front of it - and possibly pipe the output through hexdump.
> 
> One thought, does the SCV file contain exactly one line - not zero lines, not 2 lines (having one line and a newline counts as 2 lines). You may want to add "head -1"
> 
> If working in bash, you can cut things down somewhat by using Bash builtin string functions - one some of my data collection scripts, it's made a huge difference. When you use cut you are spawning two new processes (three is you add head as well).
> 
> Check the man page for parameter expansion, specifically the ${parameter#word}, ${parameter##word}, ${parameter%word},  and ${parameter%%word} forms. I think this will get you your value :
> 
> # Get the file
> Utmp=$( < /home/pi/net/devices.csv )
> 
> # Get everything after the 12th ','
> Utmp=$(Utmp#*,*,*,*,*,*,*,*,*,*,*,*,)

Always dangerous to type suggestions on the fly without testing!
(been there, done that)

I think you mean ${ ... } not $( ... ), and similarly on the next two.

> # Get everything after the first ':'
> Utmp=$(Utmp#*:)
> 
> # Optional - depends on your file, delete everything after the next , or :
> Utmp=$(Utmp%%,*) or Utmp=$(Utmp%%:*)
> 
> 
> Don't think it applies here (though I don't know if fiddling with IFS might help), but another trick you could try is using arrays. My specific action was getting traffic counts from an interface, so I have a script with :
>   Utmp=$(< /proc/net/dev)
>   Utmp=(${Utmp#*ethext:})
>   UpdateVal=${Utmp[0]}:${Utmp[8]}
> I'll leave you to figure it out.
> 
> 
> PS - no I didn't come up with this myself, someone else pointed me in that direction.
> 
> _______________________________________________
> rrd-users mailing list
> [email protected]
> https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
> 


-- 
Tony Mountifield
Work: [email protected] - http://www.softins.co.uk
Play: [email protected] - http://tony.mountifield.org