0

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.

# aggregate.sh
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

enter image description here

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

enter image description here

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
Siri
  • 1
  • 2
  • What do you get if you have the script just do one of the "rrdtool" commands and none of the filtering? – Chris Turner Feb 16 '18 at 10:44
  • 1518774900: 0.0000000000e+00 1518775200: 0.0000000000e+00 1518775500: 0.0000000000e+00 1518775800: 0.0000000000e+00 1518776100: 0.0000000000e+00 1518776400: 0.0000000000e+00 1518776700: 0.0000000000e+00 1518777000: 0.0000000000e+00 1518777300: 0.0000000000e+00 1518777600: 0.0000000000e+00 1518777900: 0.0000000000e+00 1518778200: 0.0000000000e+00 1518778500: 0.0000000000e+00 1518778800: 0.0000000000e+00 1518779100: 0.0000000000e+00 1518779400: 0.0000000000e+00 1518779700: 0.0000000000e+00 1518780000: 0.0000000000e+00 1518780300: 0.0000000000e+00 1518780600: -nan – Siri Feb 16 '18 at 11:35
  • please see in the attached image. – Siri Feb 16 '18 at 11:37
  • Can you confirm that when you run it from the console, and when you run it from cron, you are running as the same user? It might be a file permissions issue - e.g. you might be using root on the console (naughty) and your own user in cron. Check the ownership and permissions on the rrd files and their parent directories. – Steve Shipway Feb 18 '18 at 20:10
  • Thanks everyone here. Now I got the answer it maybe the first rrd file I retrieve with rrdtool fetch happens exactly every 5 minutes and the cronjob does the same with the same point in time . That's a reason why I got nan when it comes to cronjob. The solution for this is to compromise the new rrd to be late 5 minutes compared to the first rrd. – Siri Feb 19 '18 at 06:11

1 Answers1

0

Thanks everyone here. Now I got the answer it maybe the first rrd file I retrieve with rrdtool fetch happens exactly every 5 minutes and the cronjob does the same with the same point in time . That's a reason why I got nan when it comes to cronjob. The solution for this is to compromise the new rrd to be late 5 minutes compared to the first rrd.

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
Siri
  • 1
  • 2