I have been able to get the command to execute but it will not execute against all devices I have in the mysql database, it only runs against the first device. Can anyone please take a look as I know I must have made a mistake somewhere.
Here is the script
#!/usr/bin/perl
use warnings;
use strict;
use DBI;
my $dsn = 'dbi:mysql:mrtg:localhost:3306';
my $user = 'mrtg';
my $pass = 'mrtg';
my $dbh = DBI->connect($dsn, $user, $pass) or die "Cannot connect to the DB: $DBI::errstr\n";
my $sth = $dbh->prepare("select name, community, global1, global2, ifref, ifdesc, option1, option2, option3, option4, option5, template_type, template_name, filter, snmp_port, snmp_timeout, snmp_retries, snmp_backoff, snmp_version, directory from cfgmaker");
$sth->execute or die "Database select failed:" . $sth->errstr;
while (my $row = $sth->fetchrow_arrayref) {
perform_collection(@$row);
}
sub perform_collection {
my ($name, $community, $global1, $global2, $ifref, $ifdesc, $option1, $option2, $option3, $option4, $option5, $template_type, $template_name, $filter, $snmp_port, $snmp_timout, $snmp_retries, $snmp_backoff, $snmp_version, $directory) = @_;
do `cfgmaker $global1 $global2 --ifref=$ifref --ifdesc=$ifdesc $option1 $option2 $option3 $option4 $option5 --$template_type-template=$template_name '--if-filter=$filter' $community\@$name\:$snmp_port:$snmp_timout:$snmp_r etries:$snmp_backoff:$snmp_version > /var/www/mrtg/mrtg-configs/$directory/$name.cfg`
}
Thanks
James