#!/usr/bin/perl use POSIX qw(strftime); use FileHandle; use Getopt::Long; use IO::Handle; $MYSQL='/pathtomysql/mysql'; # Doing the following to get the date into consistent format my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year += 1900; my @moname = qw( 01 02 03 04 05 06 07 09 10 11 12 ); my $datestring = "$year.$moname[$mon]$mday.$hour$min.$sec"; my ($dbh,$CONTAINER,$DEBUG,$DOMAIN,$DOMTYPE,$USER,$PASSWORD,$USAGE); $Getopt::Long::autoabbrev=1; &GetOptions('-zdebug'=>\$DEBUG,'container:s'=>\$CONTAINER,'-user:s'=>\$USER,'-password:s'=>\$PASSWORD,'-x'=>\$USAGE,'v'=>\$VERSION); if ($VERSION) { print "Version 1.0 Build date: 23 May 2012 \n"; exit; } if (! $CONTAINER) { print "missing container: $CONTAINER \n"; &usage; } if (! $USER) { print "missing user: $USER\n"; &usage; } if (! $PASSWORD) { print "missing password: $PASSWORD\n"; &usage; } if ($USAGE) { &usage; } print "container: $CONTAINER \n" if $DEBUG; # This is converting it to all uppercase $CONTAINER =~ tr/a-z/A-Z/; my $TMPSQLCONT="/tmp/sql.$datestring"; my $TMPCONTLIST="/tmp/sql.contlist.$datestring"; # Getting the container ID's for the subnets that we want to get data on $SQLCONT="select user_defined_fld_value.objectid, inet_ntoa(block.STARTADDR), user_defined_fld.tag, user_defined_fld_value.VALUE from user_defined_fld_value left join user_defined_fld on user_defined_fld_value.USER_DEFINED_FLD_ID=user_defined_fld.id left join container_block on container_block.blockid=user_defined_fld_value.objectid left join block on block.id=container_block.blockid left join container on container.id=container_block.containerid where container.notes like '%$CONTAINER%'"; my $tmpcont=FileHandle->new; $tmpcont->open(">$TMPSQLCONT"); print $tmpcont "$SQLCONT;\n"; $tmpcont->close; system("$MYSQL -u $USER -p$PASSWORD instancename <$TMPSQLCONT > $TMPCONTLIST"); ######################################################################### sub usage { print "Usage: \n"; print " -c: Container \n"; print " -u: login \n"; print " -p: password\n"; print " -z: debug \n"; print " -x: This message \n"; exit 0; } #########################################################################