in reply to Parse variables from @output
Have expanded the variables further to fix more issues now.
#!/usr/local/bin/perl ## use strict; use warnings; use Data::Dumper; my @output = ( qq/Software\n/ .qq/ BIOS: version 3.6.0\n/ .qq/ kickstart: version 7.1(5)N1(1)\n/ .qq/ system: version 7.1(5)N1(1)\n/ .qq/ kickstart image file is: bootflash:\/\/\/n5000-uk9-kickstart +.7.1.5.N1.1.bin\n/ .qq/ system image file is: bootflash:\/\/\/n5000-uk9.7.1.5.N1. +1.bin\n/ .qq/Hardware\n/ .qq/ cisco Nexus 5548 Chassis ("O2 32X10GE\/Modular Universal Pla +tform Supervisor")\n/ .qq/ Intel(R) Xeon(R) CPU with 8253840 kB of memory.\n/ .qq/ Processor Board ID FOC163849D1\n/ .qq/ Device name: tpecasw01\n/ .qq/ bootflash: 2007040 kB\n/ .qq/Kernel uptime is 636 day(s), 1 hour(s), 34 minute(s), 49 secon +d(s)\n/ ); print "@output\n"; foreach (@output) { my %details; if (/^Hardware/mi) { $details{'Chassis'} = $1 if (/^\s*cisco Nexus (\S+) Chassi +s/mi); $details{'Main Memory'} = $1 if (/^\s*Intel.* with (\S+) kB of + memory/mi); $details{'Name'} = $1 if (/^\s*Device name: (\S+)/mi); $details{'Uptime'} = $1 if (/^\s*Kernel uptime is (.*?)\s*$/mi +); $details{'Version'} = $1 if (/^\s*system: .*version (\S+?)[,\s +]/mi); $details{'IOS File'} = $1 if (/^\s*system image file is:\s*"(. +*)"/mi); $details{Serial} = $1 if (/^\s*Processor board ID (\S+)/mi); $details{'ROM Version'} = $1 if (/^\s*BIOS: .*version (\S+?)[, +\s]/mi); # aka BIOS $details{'Boot Version'} = $1 if (/^\s*kickstart: .*version (\ +S+?)[,\s]/mi); # aka kickstarter $details{'Boot Flash'} = $1 if (/^\s*bootflash: (\S+)/mi); } print Dumper(\%details); }
All are working apart from $details('IOS File') is not populating/displaying. Any ideas? Result should be bootflash:///n5000-uk9.7.1.5.N1.1.bin
Value for 'IOS File' missing in results...
Software BIOS: version 3.6.0 kickstart: version 7.1(5)N1(1) system: version 7.1(5)N1(1) kickstart image file is: bootflash:///n5000-uk9-kickstart.7.1.5.N1.1 +.bin system image file is: bootflash:///n5000-uk9.7.1.5.N1.1.bin Hardware cisco Nexus 5548 Chassis ("O2 32X10GE/Modular Universal Platform Sup +ervisor") Intel(R) Xeon(R) CPU with 8253840 kB of memory. Processor Board ID FOC163849D1 Device name: tpecasw01 bootflash: 2007040 kB Kernel uptime is 636 day(s), 1 hour(s), 34 minute(s), 49 second(s) $VAR1 = { 'Uptime' => '636 day(s), 1 hour(s), 34 minute(s), 49 second( +s)', 'Serial' => 'FOC163849D1', 'Version' => '7.1(5)N1(1)', 'ROM Version' => '3.6.0', 'Main Memory' => '8253840', 'Name' => 'tpecasw01', 'Boot Version' => '7.1(5)N1(1)', 'Chassis' => '5548' };
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Parse variables from @output
by Corion (Patriarch) on Nov 15, 2019 at 15:44 UTC | |
by Cisco_Dave (Novice) on Nov 15, 2019 at 15:49 UTC | |
by Corion (Patriarch) on Nov 15, 2019 at 15:52 UTC | |
by Cisco_Dave (Novice) on Nov 15, 2019 at 15:55 UTC |
In Section
Seekers of Perl Wisdom