I have created bash file and it can run properly with console but not with crontab. In /home/zon/rrd-aggregate/agg.log
it returns nan
. But if it runs with console it shows the value from rrd correctly.
cat aggregate-rrd.sh
rm -rf /home/zon/rrd-aggregate/agg.log
rrdtool fetch /var/www/html/cacti/rra/iboss-el-srv_linux_cpu_system_4703.rrd AVERAGE |tail -2|head -n1 |cut -d":" -f2 |tr -d " " >> /home/zon/rrd-aggregate/agg.log
rrdtool fetch /var/www/html/cacti/rra/iboss-el-srv_linux_cpu_user_4704.rrd AVERAGE |tail -2|head -n1 |cut -d":" -f2 |tr -d " " >> /home/zon/rrd-aggregate/agg.log
rrdtool fetch /var/www/html/cacti/rra/iboss-el-srv_linux_cpu_nice_4702.rrd AVERAGE |tail -2|head -n1 |cut -d":" -f2 |tr -d " " >> /home/zon/rrd-aggregate/agg.log
In log file, it shows only nan.
if i run from console it works like this.
rrdtool fetch /var/www/html/cacti/rra/iboss-el-srv_linux_cpu_system_4703.rrd AVERAGE |tail -2|head -n1 |cut -d":" -f2 |tr -d " " 1.0488333333e+00
rrdtool fetch /var/www/html/cacti/rra/iboss-el-srv_linux_cpu_nice_4702.rrd AVERAGE
it shows more than this , but i just put a sample here.
1518779700: 2.2383255814e+00 1518780000: 9.6494444444e-01 1518780300: 2.0843398365e+00 1518780600: -nan
new code looks like this line as follows:
rrdtool fetch /var/www/html/cacti/rra/iboss-el-srv_linux_cpu_system_4703.rrd AVERAGE |tail -3|head -n1 |cut -d":" -f2 |tr -d " " >> /home/zon/rrd-aggregate/agg.log