<?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: PERL - help in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493106#M704732</link>
    <description>I would suggest perhaps using awk to pull the ip address out of the log file.&lt;BR /&gt;&lt;BR /&gt;You can then use dig or nslookup to get the hostname, again using awk to parse the output.&lt;BR /&gt;&lt;BR /&gt;example&lt;BR /&gt;&lt;BR /&gt;ipaddy=$(cat logfile | awk '{print $1}')&lt;BR /&gt;&lt;BR /&gt;What this does is pull out the first field in the log, space delimited and puts it in a variable called ipaddy.&lt;BR /&gt;&lt;BR /&gt;awk can use different field delimiters with this add on command.&lt;BR /&gt;&lt;BR /&gt;awk -F:&lt;BR /&gt;&lt;BR /&gt;That will use : as a field delimter.&lt;BR /&gt;&lt;BR /&gt;If you post an example of what the log looks like, I or others will happily write the script for you.&lt;BR /&gt;&lt;BR /&gt;SEP</description>
    <pubDate>Thu, 24 Feb 2005 18:21:01 GMT</pubDate>
    <dc:creator>Steven E. Protter</dc:creator>
    <dc:date>2005-02-24T18:21:01Z</dc:date>
    <item>
      <title>PERL - help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493105#M704731</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I am writing a perl script which selects some pattern from input files.&lt;BR /&gt;&lt;BR /&gt;I have used:&lt;BR /&gt;&lt;BR /&gt;$host=$1 if (/Host name:\s+(\w+)/);&lt;BR /&gt;&lt;BR /&gt;To fetch the host name from the log files.&lt;BR /&gt;&lt;BR /&gt;But I find that in some cases the file does not contain the "Host name". In such cases I have to use the name of the directory under which the files are present to represent the host name.&lt;BR /&gt;&lt;BR /&gt;Can anyone please help me. I am very new to PERL and don't have much skills in it.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Rahul</description>
      <pubDate>Thu, 24 Feb 2005 17:18:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493105#M704731</guid>
      <dc:creator>Rahul_13</dc:creator>
      <dc:date>2005-02-24T17:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: PERL - help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493106#M704732</link>
      <description>I would suggest perhaps using awk to pull the ip address out of the log file.&lt;BR /&gt;&lt;BR /&gt;You can then use dig or nslookup to get the hostname, again using awk to parse the output.&lt;BR /&gt;&lt;BR /&gt;example&lt;BR /&gt;&lt;BR /&gt;ipaddy=$(cat logfile | awk '{print $1}')&lt;BR /&gt;&lt;BR /&gt;What this does is pull out the first field in the log, space delimited and puts it in a variable called ipaddy.&lt;BR /&gt;&lt;BR /&gt;awk can use different field delimiters with this add on command.&lt;BR /&gt;&lt;BR /&gt;awk -F:&lt;BR /&gt;&lt;BR /&gt;That will use : as a field delimter.&lt;BR /&gt;&lt;BR /&gt;If you post an example of what the log looks like, I or others will happily write the script for you.&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Thu, 24 Feb 2005 18:21:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493106#M704732</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2005-02-24T18:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: PERL - help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493107#M704733</link>
      <description>Hi Steve,&lt;BR /&gt;&lt;BR /&gt;The input file looks like this:&lt;BR /&gt;&lt;BR /&gt;Host name:        mccap2&lt;BR /&gt;Time zone:        18000 EST EDT&lt;BR /&gt;UTC time:         2005-02-24T04:56:56.550&lt;BR /&gt;Local time:       2005-02-23T23:56:56.550&lt;BR /&gt;Start time (UTC): 2004-09-28T14:59:32&lt;BR /&gt;Running time:     148:13:57:24&lt;BR /&gt;...........&lt;BR /&gt;&lt;BR /&gt;I actually have written a PERL script to do the pattern search. It's not only searching for the "Host name" but also lots of other patterns.&lt;BR /&gt;&lt;BR /&gt;But the problem is that some of the log files (very few of them) does not have the "Host name" field in them.&lt;BR /&gt;&lt;BR /&gt;All these log files are stored in directories which are named after there host name. For instance the above file is taken from the directory "mccap2".&lt;BR /&gt;&lt;BR /&gt;So, first I need to verify if the file contains the "host name". If it does not I have to take this field from the name of the directory which contains the file.&lt;BR /&gt;&lt;BR /&gt;Hope my requirement is clear.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Rahul</description>
      <pubDate>Thu, 24 Feb 2005 19:19:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493107#M704733</guid>
      <dc:creator>Rahul_13</dc:creator>
      <dc:date>2005-02-24T19:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: PERL - help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493108#M704734</link>
      <description>&lt;BR /&gt;Well, do you get that directory passed in as an argument? Do you 'find' it? Do you 'glob' your way through a list?&lt;BR /&gt;&lt;BR /&gt;For example, let's assume the code looks like:&lt;BR /&gt;&lt;BR /&gt;foreach (glob "*/x.log") {&lt;BR /&gt;  open (LOG, "&amp;lt;$_") or die ...&lt;BR /&gt;  while &lt;LOG&gt;) {&lt;BR /&gt;  :&lt;BR /&gt;$host=$1 if (/Host name:\s+(\w+)/);&lt;BR /&gt;  :&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;Then you'd fix that along these lines:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;foreach (glob "*/x.log") {&lt;BR /&gt;  ($dir, $file) = split ("\/");&lt;BR /&gt;  $host = $dir; # pre-set&lt;BR /&gt;  open (LOG, "&amp;lt;$_") or die ...&lt;BR /&gt;  while &lt;LOG&gt;) {&lt;BR /&gt;  :&lt;BR /&gt;$host=$1 if (/Host name:\s+(\w+)/);&lt;BR /&gt;  :&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;So just preset $host with the directory name, and if you find the real McCoy, then it will overwrite the directory provided value.&lt;BR /&gt;&lt;BR /&gt;You could also do it after the loop that processes the log with something like&lt;BR /&gt;:&lt;BR /&gt;undef $host;&lt;BR /&gt;(or $host = "")&lt;BR /&gt;:&lt;BR /&gt;while (&lt;FILE&gt;){...&lt;BR /&gt;:&lt;BR /&gt;}&lt;BR /&gt;$host = $dir unless $host;&lt;BR /&gt;&lt;BR /&gt;Hope this helps some!&lt;BR /&gt;Hein.&lt;/FILE&gt;&lt;/LOG&gt;&lt;/LOG&gt;</description>
      <pubDate>Thu, 24 Feb 2005 23:16:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493108#M704734</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-02-24T23:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: PERL - help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493109#M704735</link>
      <description>Try as like,&lt;BR /&gt;&lt;BR /&gt;# Search all files with mccap*&lt;BR /&gt;for dir in `find $PWD -type d -name "mccap*"`; &lt;BR /&gt;do &lt;BR /&gt;  grep -q 'Host name:' $dir/*; &lt;BR /&gt;  # Host name is there&lt;BR /&gt;  if [[ $? -eq 0 ]]; &lt;BR /&gt;  then     &lt;BR /&gt;    echo "Hostname is available in $dir/$(ls $dir)"; &lt;BR /&gt;    echo "Hostname is $(awk '/Host name/ { print $3 }' $dir/*)";&lt;BR /&gt;    echo&lt;BR /&gt;  # Host name is not there then print base directory name&lt;BR /&gt;  else&lt;BR /&gt;    echo "Hostname is not available in $(ls $dir)"; &lt;BR /&gt;    echo "Hostname is $(echo $dir | awk -F "/" '{ print $NF }')"&lt;BR /&gt;    echo&lt;BR /&gt;  fi; &lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;O/P&lt;BR /&gt;Hostname is available in /home/muthu/mccap2/file&lt;BR /&gt;Hostname is mccap2&lt;BR /&gt;&lt;BR /&gt;Hostname is not available in file&lt;BR /&gt;Hostname is mccap1&lt;BR /&gt;&lt;BR /&gt;HTH.</description>
      <pubDate>Fri, 25 Feb 2005 04:02:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493109#M704735</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-02-25T04:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: PERL - help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493110#M704736</link>
      <description>Hi hein,&lt;BR /&gt;&lt;BR /&gt;My script looks like this:&lt;BR /&gt;&lt;BR /&gt;while (&amp;lt;@ARGV&amp;gt;){&lt;BR /&gt;        if (/\.(\d+)_.*.log/) {&lt;BR /&gt;        $date = $1;&lt;BR /&gt;        open (INP, "&amp;lt;$_") or die "Could not open file '$_' for input";&lt;BR /&gt;                while(&lt;INP&gt;) {&lt;BR /&gt;                $host=$1 if (/Host name:\s+(\w+)/);&lt;BR /&gt;....................&lt;BR /&gt;....................&lt;BR /&gt; print join(",",$host,$date,$name,$num),"\n";&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Whenever, the Host name is not there in the input files, it is just coming as blank. SO, I want the name of the directory to be used for the host name when the host name is missing.&lt;BR /&gt;&lt;BR /&gt;I tried using:&lt;BR /&gt;&lt;BR /&gt;while (&amp;lt;@ARGV&amp;gt;){&lt;BR /&gt;($dir, $file) = split ("\/");&lt;BR /&gt;$host = $dir; # pre-set&lt;BR /&gt;....&lt;BR /&gt;&lt;BR /&gt;But I got the name of the file in the host field. I want the name of the directory to be in the host.&lt;BR /&gt;&lt;BR /&gt;Can you please help.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Rahul&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/INP&gt;</description>
      <pubDate>Fri, 25 Feb 2005 15:13:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493110#M704736</guid>
      <dc:creator>Rahul_13</dc:creator>
      <dc:date>2005-02-25T15:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: PERL - help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493111#M704737</link>
      <description>you could use the File::Basname module to make it easy. &lt;BR /&gt;&lt;BR /&gt;use File::Basename&lt;BR /&gt;&lt;BR /&gt;while (&amp;lt;@ARGV&amp;gt;) {&lt;BR /&gt;   ($fname, $fpath)=fileparse($_);&lt;BR /&gt;   $host = $fpath if (!length $host);   &lt;BR /&gt;}</description>
      <pubDate>Fri, 25 Feb 2005 16:56:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493111#M704737</guid>
      <dc:creator>Marvin Strong</dc:creator>
      <dc:date>2005-02-25T16:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: PERL - help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493112#M704738</link>
      <description>Hi Marvin,&lt;BR /&gt;&lt;BR /&gt;I am getting the follwoing erro while using Basename:&lt;BR /&gt;&lt;BR /&gt;Can't locate File/Basename.pm in @INC (@INC contains: /opt/perl5/lib/5.00502/PA-RISC1.1 /opt/perl5/lib/5&lt;BR /&gt;.00502 /opt/perl5/lib/site_perl/5.005/PA-RISC1.1 /opt/perl5/lib/site_perl/5.005 .) at repext.pl line 5.&lt;BR /&gt;&lt;BR /&gt;Is there any other way to accomplish my requirements.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Rahul&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 25 Feb 2005 17:31:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493112#M704738</guid>
      <dc:creator>Rahul_13</dc:creator>
      <dc:date>2005-02-25T17:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: PERL - help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493113#M704739</link>
      <description>&lt;BR /&gt;&lt;BR /&gt;Start your perl script with:&lt;BR /&gt;&lt;BR /&gt;use Cwd;&lt;BR /&gt;&lt;BR /&gt;Then while in the loop print out cwd.&lt;BR /&gt;See how you can use that to find the current dir. Possibly you may need something like:&lt;BR /&gt;&lt;BR /&gt;use Cwd;&lt;BR /&gt;use File::Spec;&lt;BR /&gt;:&lt;BR /&gt;loop&lt;BR /&gt;:&lt;BR /&gt;$absdir = File::Spec-&amp;gt;catdir(cwd,$_);&lt;BR /&gt;$host = substr($absdir,rindex($absdir,"/")+1);&lt;BR /&gt;:&lt;BR /&gt;&lt;BR /&gt;untested!&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;File::Spec-&amp;gt;catdir(cwd&lt;BR /&gt;</description>
      <pubDate>Sat, 26 Feb 2005 01:35:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3493113#M704739</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-02-26T01:35:01Z</dc:date>
    </item>
  </channel>
</rss>

