######################################################################### # Begin small slice of ciscoconf.pl use Data::Dumper; #only for testing use vars qw( $section $timeout @timeout $target @targets $command @commands ); my $conf = 'ciscoconf.conf'; # list of target devices and commands my $tmp = 'ciscoconf.tmp'; my $log = 'ciscoconf.log'; #&CONFINT(); &CONFEXT(); ------------------------------------------------------------------------- sub CONFINT { $timeout = '15'; @targets = ('192.168.1.27','172.16.0.138' ); @commands = ( 'sho clo', 'set leng 0', 'term leng 0', 'sho clo', 'disa', ); open (DUMP, "> ciscoconfint.dump") or die "Error opening ciscoconfint.dump for write: $!"; print DUMP Dumper(@timeout), "\n"; print DUMP Dumper(@targets), "\n"; print DUMP Dumper(@commands), "\n"; close (DUMP) or die "Error closing ciscoconfint.dump after write: $!"; } ------------------------------------------------------------------------- sub CONFEXT { open (CONF, "<$conf") or die "Error opening $conf for read: $!"; while () { next if /^#/ or /^s.*$/ or /^!/; # ignore comment lines chomp; if (/^\[([^\]]+)\]/) { $section = $1; next; } else { if ($section =~ /timeout/i) { push @timeout,$_; } if ($section =~ /targets/i) { push @targets,$_; } if ($section =~ /commands/i) { push @commands,$_; } } } close (CONF) or die " ciscoconf.pl: Error closing $conf after read: $!"; open (DUMP, "> ciscoconfext.dump") or die "Error opening ciscoconfext.dump for write: $!"; print DUMP Dumper(@timeout), "\n"; print DUMP Dumper(@targets), "\n"; print DUMP Dumper(@commands), "\n"; close (DUMP) or die "Error closing ciscoconfext.dump after write: $!"; } # End small slice of ciscoconf.pl ######################################################################### # begin ciscoconf.conf [Timeout] 15 [Targets] 192.168.1.27 172.16.0.138 [Commands] sho clo set leng 0 term leng 0 disa sho clo # end ciscoconf.conf ######################################################################### # begin ciscoconfext.dump $VAR1 = 15; $VAR2 = ''; $VAR1 = '192.168.1.27'; $VAR2 = '172.16.0.138'; $VAR3 = ''; $VAR1 = 'term leng 0'; $VAR2 = 'disa'; # end ciscoconfext.dump ######################################################################### # begin ciscoconfint.dump $VAR1 = 15; $VAR1 = '192.168.1.27'; $VAR2 = '172.16.0.138'; $VAR1 = 'sho clo'; $VAR2 = 'set leng 0'; $VAR3 = 'term leng 0'; $VAR4 = 'sho clo'; $VAR5 = 'disa'; # end ciscoconfint.dump #########################################################################