<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Basic perl script in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810369#M100089</link>
    <description>&amp;gt; I am trying to get rid of the brackets&lt;BR /&gt;&amp;gt; around&lt;BR /&gt;&amp;gt; list 0 Target[10.79.192.254_10.79.230.62]&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt; I must convert that line to look like&lt;BR /&gt;&amp;gt; 10.79.192.254_10.79.230.62.html&lt;BR /&gt;&lt;BR /&gt;s{.*\bTarget\s*\[([^]+)\]}{$1.html};&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;s{.*Target\s*\[\s*}{} &amp;amp;&amp;amp; s{\s*\].*}{.html};&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
    <pubDate>Thu, 22 Jun 2006 08:18:34 GMT</pubDate>
    <dc:creator>H.Merijn Brand (procura</dc:creator>
    <dc:date>2006-06-22T08:18:34Z</dc:date>
    <item>
      <title>Basic perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810366#M100086</link>
      <description>Hi there, I am trying to write a script using perl, and need some help.&lt;BR /&gt;I have a mrtg.cfg file that I would like to build a web page from.&lt;BR /&gt;&lt;BR /&gt;My problem is I am trying to find a quick way to select 2 fields that I want to convert as a url. The fields that I am interested are those that start with Target, which is the name of the URL that I want to point to and the Description is the name that I would like to give that link.&lt;BR /&gt;&lt;BR /&gt;Can someone maybe just show me how to pull those values into a variable or array, and I should be able to go on from there.&lt;BR /&gt;&lt;BR /&gt;I have attached the input file . This is what I have tried so far.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#! /usr/bin/perl&lt;BR /&gt;open FI, "#open FO, "&amp;gt;&amp;gt;/var/apache/htdocs/mrtgweb.html;&lt;BR /&gt;while ($line=&lt;FI&gt;)&lt;BR /&gt; {&lt;BR /&gt;#@LIST=(split/;/,($line));&lt;BR /&gt;@LIST=($line);&lt;BR /&gt;print @LIST[0];&lt;BR /&gt;print @LIST[1];&lt;BR /&gt;sleep 1;&lt;BR /&gt;}&lt;BR /&gt;exit;&lt;BR /&gt;~&lt;BR /&gt;&lt;BR /&gt;&lt;/FI&gt;</description>
      <pubDate>Thu, 22 Jun 2006 01:44:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810366#M100086</guid>
      <dc:creator>Steve_617</dc:creator>
      <dc:date>2006-06-22T01:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: Basic perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810367#M100087</link>
      <description>open FI, "while (&lt;FI&gt;)&lt;BR /&gt;{&lt;BR /&gt;  if ($_ =~ /Description/ || $_ =~ /Target/) {&lt;BR /&gt;    @LIST=split/:/;&lt;BR /&gt;    print "$LIST[0]\n";&lt;BR /&gt;    print "$LIST[1]\n";&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;close FI;&lt;BR /&gt;&lt;/FI&gt;</description>
      <pubDate>Thu, 22 Jun 2006 02:32:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810367#M100087</guid>
      <dc:creator>Marcin Golembski_1</dc:creator>
      <dc:date>2006-06-22T02:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: Basic perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810368#M100088</link>
      <description>Ok I thought I would be able to continue.&lt;BR /&gt;I am trying to get rid of the brackets around&lt;BR /&gt;list 0 Target[10.79.192.254_10.79.230.62]&lt;BR /&gt;&lt;BR /&gt;I must convert that line to look like&lt;BR /&gt;10.79.192.254_10.79.230.62.html&lt;BR /&gt;&lt;BR /&gt;What I tried to do was&lt;BR /&gt;#! /usr/bin/perl&lt;BR /&gt;if ($_ =~ /Description/ || $_ =~ /Target/) {&lt;BR /&gt;@LIST=split/:/;&lt;BR /&gt;#$ULINK = $LIST[0];&lt;BR /&gt;$ULINK = split { '\[\]' , $LIST[0]};&lt;BR /&gt;$UNAME = $LIST[2];&lt;BR /&gt;&lt;BR /&gt;#print "list 1 $LIST[1]\n";&lt;BR /&gt;print "list 0 $LIST[0]\n";&lt;BR /&gt;print "list 2 $LIST[2]\n";&lt;BR /&gt;print "link is $ULINK\n" ;&lt;BR /&gt;print "name is $UNAME\n" ;&lt;BR /&gt;print "\n\n\n";&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;close FI;</description>
      <pubDate>Thu, 22 Jun 2006 07:42:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810368#M100088</guid>
      <dc:creator>Steve_617</dc:creator>
      <dc:date>2006-06-22T07:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: Basic perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810369#M100089</link>
      <description>&amp;gt; I am trying to get rid of the brackets&lt;BR /&gt;&amp;gt; around&lt;BR /&gt;&amp;gt; list 0 Target[10.79.192.254_10.79.230.62]&lt;BR /&gt;&amp;gt;&lt;BR /&gt;&amp;gt; I must convert that line to look like&lt;BR /&gt;&amp;gt; 10.79.192.254_10.79.230.62.html&lt;BR /&gt;&lt;BR /&gt;s{.*\bTarget\s*\[([^]+)\]}{$1.html};&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;s{.*Target\s*\[\s*}{} &amp;amp;&amp;amp; s{\s*\].*}{.html};&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Thu, 22 Jun 2006 08:18:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810369#M100089</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2006-06-22T08:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: Basic perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810370#M100090</link>
      <description>if($_ =~ /Target/) {&lt;BR /&gt;    @LIST=split/:/;&lt;BR /&gt;    $LIST[0] =~ s/.*Target\[(.*)\]/$1/;&lt;BR /&gt;    $LIST[0] .= ".html";&lt;BR /&gt;    print "$LIST[0]\n";&lt;BR /&gt;  }&lt;BR /&gt;</description>
      <pubDate>Thu, 22 Jun 2006 08:28:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810370#M100090</guid>
      <dc:creator>Marcin Golembski_1</dc:creator>
      <dc:date>2006-06-22T08:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Basic perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810371#M100091</link>
      <description>if($_ =~ /Target/) {&lt;BR /&gt;    @LIST=split/:/;&lt;BR /&gt;    $LIST[0] =~ s/.*Target\[(.*)\]/$1\.html/;&lt;BR /&gt;    print "$LIST[0]\n";&lt;BR /&gt;  }&lt;BR /&gt;</description>
      <pubDate>Thu, 22 Jun 2006 08:31:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810371#M100091</guid>
      <dc:creator>Marcin Golembski_1</dc:creator>
      <dc:date>2006-06-22T08:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: Basic perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810372#M100092</link>
      <description>Here are some regexprs which my help.&lt;BR /&gt;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;  next if /^\s*#/;   # skip comment lines&lt;BR /&gt;  $ip = $1 if /Target\[([0-9._]+)\]/;&lt;BR /&gt;  if (/Desc.*TD&amp;gt;(.*)&amp;lt;\/TD/) {&lt;BR /&gt;    $desc = $1;&lt;BR /&gt;    print "ip = $ip, desc = $desc\n";&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Sample output:&lt;BR /&gt;&lt;BR /&gt;ip = 10.79.192.254_10.79.230.58, desc = GigabitEthernet0/3&lt;BR /&gt;&lt;BR /&gt;Enjoy&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Thu, 22 Jun 2006 08:37:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810372#M100092</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2006-06-22T08:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: Basic perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810373#M100093</link>
      <description>&lt;!--!*#--&gt;Hey; &lt;BR /&gt;&lt;BR /&gt;I'd probably do it as follows:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;&lt;BR /&gt;open FI, $ARGV[0];&lt;BR /&gt;my @lines= &lt;FI&gt;;&lt;BR /&gt;my $lines = join('', @lines);&lt;BR /&gt;&lt;BR /&gt;while ($lines =~ m{^Target(.*?)}mgs)&lt;BR /&gt;{  my $stanza = $1;&lt;BR /&gt;   my ($url) = $stanza =~ m{\[(.*?)\].*};&lt;BR /&gt;   my ($desc) = $stanza =~ m{.*Description:(.*?).*};&lt;BR /&gt;   print "URL:  $url.html\n";&lt;BR /&gt;   print "Desc: $desc\n";&lt;BR /&gt;   print "-" x 40 . "\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Sample output, using your data file:&lt;BR /&gt;URL:  10.79.192.254_10.255.200.1.html&lt;BR /&gt;Desc: GigabitEthernet0/3  &lt;BR /&gt;----------------------------------------&lt;BR /&gt;URL:  10.79.192.254_10.79.226.174.html&lt;BR /&gt;Desc: Serial4/0 CXMM City Deep 370707-00004-01 &lt;BR /&gt;----------------------------------------&lt;BR /&gt;URL:  10.79.192.254_10.79.230.58.html&lt;BR /&gt;Desc: Serial3/0:17 Welgedaght Hostel Cct number 280707-03942-01 &lt;BR /&gt;----------------------------------------&lt;BR /&gt;&lt;BR /&gt;&lt;/FI&gt;</description>
      <pubDate>Thu, 22 Jun 2006 08:50:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810373#M100093</guid>
      <dc:creator>Doug O'Leary</dc:creator>
      <dc:date>2006-06-22T08:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: Basic perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810374#M100094</link>
      <description>open FI, $ARGV[0];&lt;BR /&gt;my @lines= &lt;FI&gt;;&lt;BR /&gt;my $lines = join('', @lines);&lt;BR /&gt;&lt;BR /&gt;as FI is in ARGV, this is easier written using&lt;BR /&gt;&lt;BR /&gt;my $lines = join " ", &amp;lt;&amp;gt;;&lt;BR /&gt;&lt;BR /&gt;if FI's name was not in @ARGV, you can fake that&lt;BR /&gt;&lt;BR /&gt;my $lines;&lt;BR /&gt;{   local @ARGV = ("file.name");&lt;BR /&gt;    $lines = join " ", &amp;lt;&amp;gt;;&lt;BR /&gt;    }&lt;BR /&gt;&lt;BR /&gt;Whatever of the above is used, the remaining $lines still contains all the newlines&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn&lt;/FI&gt;</description>
      <pubDate>Thu, 22 Jun 2006 08:59:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810374#M100094</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2006-06-22T08:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: Basic perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810375#M100095</link>
      <description>Hi Guys&lt;BR /&gt;Thanks for all your input. My script is working, and I am sharing it. Still a novice, so any suggestions and enhancements from you guys would help.&lt;BR /&gt;Thanks again for everybody's input&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;&lt;BR /&gt;unlink "/var/apache/htdocs/tmp1.html";&lt;BR /&gt;&lt;BR /&gt;@FILES=`ls /var/apache/htdocs/cfg/*.cfg`;&lt;BR /&gt;foreach $FILE (@FILES) {&lt;BR /&gt;    print ($FILE);&lt;BR /&gt;&lt;BR /&gt;open FO, "&amp;gt;&amp;gt; /var/apache/htdocs/tmp1.html" or die;&lt;BR /&gt;open FI, "&amp;lt;$FILE" or die;&lt;BR /&gt;#open FI, "#open FI, $ARGV[0];&lt;BR /&gt;my @lines= &lt;FI&gt;;&lt;BR /&gt;my $lines = join('', @lines);&lt;BR /&gt;&lt;BR /&gt;my @NAMER=split(/\//, $FILE);&lt;BR /&gt;print " $NAMER[5] \n";&lt;BR /&gt;my @NAMER1=split('.cfg', $NAMER[5]);&lt;BR /&gt;&lt;BR /&gt;print "printing file @NAMER \n";&lt;BR /&gt;print " four $NAMER1[4] \n";&lt;BR /&gt;print " zero $NAMER1[0] \n";&lt;BR /&gt;print " one $NAMER1[1] \n";&lt;BR /&gt;#&lt;BR /&gt;&lt;BR /&gt;print FO "&lt;BR /&gt;";&lt;BR /&gt;&lt;BR /&gt;print FO "";&lt;BR /&gt;print FO "";&lt;BR /&gt;print FO "&lt;TITLE&gt; Welcome to Infoman Report CEntre &lt;/TITLE&gt;";&lt;BR /&gt;print FO "&amp;lt;meta http-equiv="refresh" content="60#;" url="http://196.9.207.23/tmp1.html" /&amp;gt;";&lt;BR /&gt;print FO " &amp;lt; circle="" outside=""&amp;gt;" ;&lt;BR /&gt;#echo \&lt;H5&gt;\&lt;SPAN style="'color:red' style=font:16.0pt'"&gt;$spoavg\&lt;P&gt;\&lt;/P&gt;\&lt;/SPAN&gt;\&lt;/H5&gt; &amp;gt;&amp;gt;/tmp/tmp200&lt;BR /&gt;print FO "  MRTG Statistics for Distribution $NAMER1[0] ";&lt;BR /&gt;print FO "&lt;BR /&gt;\n";&lt;BR /&gt;print FO "";&lt;BR /&gt;print FO "";&lt;BR /&gt;print FO "&lt;BR /&gt;";&lt;BR /&gt;print FO "";&lt;BR /&gt;&lt;BR /&gt;while ($lines =~ m{^Target(.*?)}mgs)&lt;BR /&gt;{  my $stanza = $1;&lt;BR /&gt;   my ($url) = $stanza =~ m{\[(.*?)\].*};&lt;BR /&gt;   my ($desc) = $stanza =~ m{.*Description:(.*?).*};&lt;BR /&gt;  # print FO "URL:  $url.html\n";&lt;BR /&gt;  # print FO "Desc: $desc\n";&lt;BR /&gt;   print FO "&lt;A href="\&amp;quot;/mrtg/10.79.192.254/$url.html\&amp;quot;" target="_blank"&gt; Desc: $desc&lt;/A&gt;\n";&lt;BR /&gt;   print FO "&lt;BR /&gt;\n";&lt;BR /&gt;   print "-" x 40 . "\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;print FO "";&lt;BR /&gt;close FO;&lt;BR /&gt;exit;&lt;/FI&gt;</description>
      <pubDate>Fri, 23 Jun 2006 03:44:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810375#M100095</guid>
      <dc:creator>Steve_617</dc:creator>
      <dc:date>2006-06-23T03:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: Basic perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810376#M100096</link>
      <description>&lt;!--!*#--&gt;Just How I would write it ...&lt;BR /&gt;&lt;BR /&gt;--8&amp;lt;---&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;&lt;BR /&gt;use strict;   # Never write without it&lt;BR /&gt;use warnings; # Shows you what you wanted to know&lt;BR /&gt;&lt;BR /&gt;my $html_file = "/var/apache/htdocs/tmp1.html";&lt;BR /&gt;unlink $html_file;&lt;BR /&gt;open my $html, "&amp;gt;", $html_file or die "$html_file: $!";&lt;BR /&gt;&lt;BR /&gt;foreach my $ifile (glob "/var/apache/htdocs/cfg/*.cfg") {&lt;BR /&gt;    print STDERR "$ifile ...\n";&lt;BR /&gt;    local (@ARGV, $/) = ($ifile);&lt;BR /&gt;    $lines = &amp;lt;&amp;gt;;&lt;BR /&gt;&lt;BR /&gt;    (my $dist_name = $ifile) =~ s{.*/[^/]+.cfg$}{$1};&lt;BR /&gt;&lt;BR /&gt;    print $html &amp;lt;&amp;lt; EOH;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;  &lt;TITLE&gt;Welcome to Infoman Report Centre&lt;/TITLE&gt;&lt;BR /&gt;  &amp;lt;meta http-equiv="refresh" content="60#" /&amp;gt;&lt;BR /&gt;  &amp;lt; circle="" outside=""&amp;gt;&lt;BR /&gt;  MRTG Statistics for Distribution $dist_name&lt;BR /&gt;  &lt;BR /&gt;&lt;BR /&gt;  &lt;BR /&gt;&lt;BR /&gt;EOH&lt;BR /&gt;&lt;BR /&gt;    while ($lines =~ m{^Target(.*?)}mgs) {&lt;BR /&gt;        my $stanza = $1;&lt;BR /&gt;        my ($url)  = $stanza =~ m{\[(.*?)\].*};&lt;BR /&gt;        my ($desc) = $stanza =~ m{.*Description:(.*?).*}i;&lt;BR /&gt;        print $html qq{&lt;A href="https://community.hpe.com/mrtg/10.79.192.254/$url.html" target="_blank"&gt;Desc: $desc&lt;/A&gt;\n", &lt;BR .="" /&gt;\n";&lt;BR /&gt;        print STDERR "-" x 40, "\n";&lt;BR /&gt;        }&lt;BR /&gt;    }&lt;BR /&gt;&lt;BR /&gt;print $html "\n\n";&lt;BR /&gt;close $html;&lt;BR /&gt;--&amp;gt;8---&lt;BR /&gt;&lt;BR /&gt;Though I have serious doubt about this whole script.&lt;BR /&gt;&lt;BR /&gt;I have already altered you HTML generation, as it was very wrong. Mine still isn't w3c compliant, but I have removed several parts already.&lt;BR /&gt;&lt;BR /&gt;You are generating a single html file with several  starts, each had two  calls in your original, &lt;BR /&gt; inside a  section and much more.&lt;BR /&gt;&lt;BR /&gt;Have a look at the final outcome, and see if this is really what you want. I hope it's not.&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Fri, 23 Jun 2006 04:16:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-perl-script/m-p/3810376#M100096</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2006-06-23T04:16:39Z</dc:date>
    </item>
  </channel>
</rss>

