[rrd-users] RRDTOOL Update with script in string

Tony Mountifield tony at mountifield.org
Fri Jan 15 18:18:29 CET 2016

In article <1931F5F1-EFE3-44B2-A764-272FE0543755 at thehobsons.co.uk>,
Simon Hobson <linux at thehobsons.co.uk> wrote:
> maxmax20 <mak.admin at zoho.com> 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
> rrd-users at lists.oetiker.ch
> https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users

Tony Mountifield
Work: tony at softins.co.uk - http://www.softins.co.uk
Play: tony at mountifield.org - http://tony.mountifield.org

More information about the rrd-users mailing list