[rrd-users] RRDTOOL Update with script in string
Simon Hobson
linux at thehobsons.co.uk
Fri Jan 15 14:50:37 CET 2016
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#*,*,*,*,*,*,*,*,*,*,*,*,)
# 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.
More information about the rrd-users
mailing list