[rrd-users] extract command line options used to create an RRD file

a.smith at ukgrid.net a.smith at ukgrid.net
Tue Jul 6 14:19:09 CEST 2010


Here is my broken code, basically when I read in $create and use it to  
create an RRD file in the same script as per the example in the  
RRDs.pm everything works. When I use a script to write the value of  
$create to a file, then reread that file by running the script in  
import mode it fails with an error (depending on if I escape \@$create  
or not it gives two different errors). I cant think what issue there  
could be, excepting I dont understand the syntax @$ so perhaps its  
that. Any ideas? TIA!

#!/usr/local/bin/perl

use lib "/usr/local/smokeping/lib";
use Smokeping::RRDtools;
use File::Basename;
use RRDs;

#use strict;
use warnings;

my $dir = "/usr/home/cacti/rra";
my $exportdir = "/usr/home/cacti/rraexport";
my @rrds = glob "$dir/*.rrd";
my @rrdsimport = glob "$exportdir/*.rrd";
my $fh;
my $mode;
my $basename;

# read first cmd line arguement
$mode = shift;

unless ($mode) {
   print "usage: rrdtrans.pl export|import\n";
   exit;
}

if ($mode eq "export") {
   foreach (@rrds) {
         #print $_;
         # get the create arguments that $file was created with
         my $create = Smokeping::RRDtools::info2create($_);
         my $basename = basename($_);
         open (my $fh, '>', "$exportdir/$basename") or die "Couldn't open: fh";
         print $fh "$create";
         undef $fh;
         print "$create\n";
   }
}
elsif ($mode eq "import") {
   foreach (@rrdsimport) {
         my $basename = basename($_);
         unless (-e "$dir/$basename") {
         open (my $fh, '<', $_) or die "Couldn't open: fh";
         my($create) = <$fh>;
         #chomp($create);
         print "Create file $dir/$basename with data $create\n";
         my $ERR;
         RRDs::create("$dir/$basename", \@$create);
         #RRDs::create("$dir/$basename", @$create);
         $ERR=RRDs::error;
           if($ERR) {
           print "$0: ERROR creating $dir/$basename: my $ERR\n"
           }
         undef $fh;
         }
   }
}
else
{
   print "usage: rrdtrans.pl export|import\n";
}





More information about the rrd-users mailing list