<?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: New to scripting, grateful for any help !! in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558685#M678992</link>
    <description>&lt;!--!*#--&gt;Hi Jeremy:&lt;BR /&gt;&lt;BR /&gt;Here's a suggestion:&lt;BR /&gt;&lt;BR /&gt;# cat ./watch&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;REFFILE=/tmp/REF.$$&lt;BR /&gt;touch ${REFFILE}&lt;BR /&gt;while true&lt;BR /&gt;do&lt;BR /&gt;    ls | while read FILE&lt;BR /&gt;    do&lt;BR /&gt;        [ ${FILE} -nt ${REFFILE} ] || continue&lt;BR /&gt;        awk 'NR==12 &amp;amp;&amp;amp; /ABORT/ {print FILENAME":"$0;exit 0}' ${FILE}&lt;BR /&gt;    done&lt;BR /&gt;    touch ${REFFILE}&lt;BR /&gt;    sleep 600&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Change to the directory of interest.  The script assumes that only text files are present (no other directories).  This is easily rectified if necessasry.&lt;BR /&gt;&lt;BR /&gt;The script runs infinitely until killed.  It awakens every 5-minutes (600 seconds) to look for the string "ABORT" on line-12 of files that have been modified more recently than 5-minutes ago.  If it finds a match to this criteria, the script prints the filename along with the contents of the 12th line.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Tue, 05 Jan 2010 17:27:05 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2010-01-05T17:27:05Z</dc:date>
    <item>
      <title>New to scripting, grateful for any help !!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558682#M678989</link>
      <description>Hi all,&lt;BR /&gt;I've been asked to create a script that will look for a particular string in a particular directory which contains anything upto 15000 files.&lt;BR /&gt;On line 12 of every file within the directory there is a possibility of the work 'ABORT', any other occurences of the word abort withing the files I need to ignore, only the one on line 12 is important.&lt;BR /&gt;ABORT is the string I need to look for and I would like to poll the directory every 5 mins (presumably via a cron job), and look at the new files that have been created. &lt;BR /&gt;&lt;BR /&gt;Grateful for any help.</description>
      <pubDate>Tue, 05 Jan 2010 15:27:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558682#M678989</guid>
      <dc:creator>Jeremy W</dc:creator>
      <dc:date>2010-01-05T15:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: New to scripting, grateful for any help !!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558683#M678990</link>
      <description>"ABORT is the string I need to look for and I would like to poll the directory every 5 mins (presumably via a cron job), and look at the new files that have been created."&lt;BR /&gt;&lt;BR /&gt;dumb question....do you only need to examine the files create since the previous run, or should all the files be examined? (I'd assume the former, as you've already looked at the existing files, but if they can be overwritten, then they would be candidates as well...)</description>
      <pubDate>Tue, 05 Jan 2010 16:17:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558683#M678990</guid>
      <dc:creator>OldSchool</dc:creator>
      <dc:date>2010-01-05T16:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: New to scripting, grateful for any help !!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558684#M678991</link>
      <description>&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;ls /dir &amp;gt; WORK_FILE  (* get ALL files *)&lt;BR /&gt;cat $WORK_FILE | while read a  (* read a file *)&lt;BR /&gt;do&lt;BR /&gt;   i=0&lt;BR /&gt;   cat $a | while read b (* read a line *)&lt;BR /&gt;   do&lt;BR /&gt;      if [[ $i -eq 12 ]]  (* if 12th line *)&lt;BR /&gt;      then&lt;BR /&gt;         grep ABORT $b  (* check for ABORT *)&lt;BR /&gt;         if [[ $? -eq 0 ]]&lt;BR /&gt;         then&lt;BR /&gt;            TRUE=0&lt;BR /&gt;         fi&lt;BR /&gt;         break&lt;BR /&gt;      fi&lt;BR /&gt;      i=(($i+1))&lt;BR /&gt;   done&lt;BR /&gt;done</description>
      <pubDate>Tue, 05 Jan 2010 17:08:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558684#M678991</guid>
      <dc:creator>Michael Steele_2</dc:creator>
      <dc:date>2010-01-05T17:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: New to scripting, grateful for any help !!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558685#M678992</link>
      <description>&lt;!--!*#--&gt;Hi Jeremy:&lt;BR /&gt;&lt;BR /&gt;Here's a suggestion:&lt;BR /&gt;&lt;BR /&gt;# cat ./watch&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;REFFILE=/tmp/REF.$$&lt;BR /&gt;touch ${REFFILE}&lt;BR /&gt;while true&lt;BR /&gt;do&lt;BR /&gt;    ls | while read FILE&lt;BR /&gt;    do&lt;BR /&gt;        [ ${FILE} -nt ${REFFILE} ] || continue&lt;BR /&gt;        awk 'NR==12 &amp;amp;&amp;amp; /ABORT/ {print FILENAME":"$0;exit 0}' ${FILE}&lt;BR /&gt;    done&lt;BR /&gt;    touch ${REFFILE}&lt;BR /&gt;    sleep 600&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Change to the directory of interest.  The script assumes that only text files are present (no other directories).  This is easily rectified if necessasry.&lt;BR /&gt;&lt;BR /&gt;The script runs infinitely until killed.  It awakens every 5-minutes (600 seconds) to look for the string "ABORT" on line-12 of files that have been modified more recently than 5-minutes ago.  If it finds a match to this criteria, the script prints the filename along with the contents of the 12th line.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 05 Jan 2010 17:27:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558685#M678992</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-01-05T17:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: New to scripting, grateful for any help !!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558686#M678993</link>
      <description>&lt;!--!*#--&gt;&amp;gt;On line 12 of every file within the directory there is a possibility of the word 'ABORT',&lt;BR /&gt;&lt;BR /&gt;Once a new file is found (see below), you can scan it with awk:&lt;BR /&gt;awk '&lt;BR /&gt;NR &amp;gt; 12 { exit }&lt;BR /&gt;/ABORT/ {&lt;BR /&gt;   if (NR &amp;lt; 12) next&lt;BR /&gt;   print $0&lt;BR /&gt;}' file&lt;BR /&gt;&lt;BR /&gt;&amp;gt;OldSchool: do you only need to examine the files created since the previous run, or should all the files be examined?&lt;BR /&gt;&lt;BR /&gt;Kind of hard to find created files unless you keep tract of all 15,000 files.  Unless you look at the inode change time.  This would probably be faster than looking at the modification time, if files are continually being appended.&lt;BR /&gt;&lt;BR /&gt;This seems like it needs a reference file and use find with -newer.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;JRF: awk 'NR==12 &amp;amp;&amp;amp; /ABORT/ {print FILENAME":"$0;exit 0}' ${FILE}&lt;BR /&gt;&lt;BR /&gt;(Before I submitted, I noticed your solution.)&lt;BR /&gt;It seems you have the same idea, unfortunately you'll need to break out of awk if NR &amp;gt; 12, or you'll be wasting time scanning large files.</description>
      <pubDate>Tue, 05 Jan 2010 17:49:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558686#M678993</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-01-05T17:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: New to scripting, grateful for any help !!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558687#M678994</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Dennis: (Before I submitted, I noticed your solution.) It seems you have the same idea, unfortunately you'll need to break out of awk if NR &amp;gt; 12, or you'll be wasting time scanning large files.&lt;BR /&gt;&lt;BR /&gt;Yes, indeed, you're right and I meant to add that akin to the exit I did upon matching.  We could change:&lt;BR /&gt;&lt;BR /&gt;awk 'NR==12 &amp;amp;&amp;amp; /ABORT/ {print FILENAME":"$0;exit 0}' ${FILE}&lt;BR /&gt;&lt;BR /&gt;...to:&lt;BR /&gt;&lt;BR /&gt;awk 'NR&amp;gt;12 {exit 0};NR==12 &amp;amp;&amp;amp; /ABORT/ {print FILENAME":"$0;exit 0}' ${FILE}&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 05 Jan 2010 17:57:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558687#M678994</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-01-05T17:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: New to scripting, grateful for any help !!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558688#M678995</link>
      <description>Dennis: This would probably be faster than looking at the modification time, if files are continually being appended.&lt;BR /&gt;&lt;BR /&gt;Right, but the problem to be solved has that one ill-defined item.  I suspect that having "looked" at at file in one pass, he may never need to "look" at it again.  Other possibilites include moving all of the files examined in one pass to a different directory after examination, keeping a listing from the previous run and removing removing those entries from the current run with some combination of sort and diff....I'm sure their are other ways as well..</description>
      <pubDate>Tue, 05 Jan 2010 18:23:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558688#M678995</guid>
      <dc:creator>OldSchool</dc:creator>
      <dc:date>2010-01-05T18:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: New to scripting, grateful for any help !!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558689#M678996</link>
      <description>Many thanks for your replies. Dennis is correct, once a file has been checked, there isn't a need to check that file again. Files only need to be check once each. If the string is found the script needs to exit that time, but to continue to run again after another 5 minute pause, (if that's possible).&lt;BR /&gt;&lt;BR /&gt;Is it possible to check for new files without creating reference files, as they would require housekeeping as well.&lt;BR /&gt;&lt;BR /&gt;Apologies for what may seem basic questions, but very very new to all this !!!&lt;BR /&gt;&lt;BR /&gt;Jeremy</description>
      <pubDate>Wed, 06 Jan 2010 10:40:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558689#M678996</guid>
      <dc:creator>Jeremy W</dc:creator>
      <dc:date>2010-01-06T10:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: New to scripting, grateful for any help !!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558690#M678997</link>
      <description>&lt;!--!*#--&gt;Hi (again) Jeremy:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; ...once a file has been checked, there isn't a need to check that file again. Files only need to be check once each. If the string is found the script needs to exit that time, but to continue to run again after another 5 minute pause, (if that's possible).&lt;BR /&gt;&lt;BR /&gt;That's the essence of the outer loop (while true...).  This loop ends with a 5-minute sleep before running again.&lt;BR /&gt;&lt;BR /&gt;Notice the line:&lt;BR /&gt;&lt;BR /&gt;[ ${FILE} -nt ${REFFILE} ] || continue&lt;BR /&gt;&lt;BR /&gt;This says to compare the modification time of the file to a reference file and if the file hasn't been modified during the last interval, continue with the next file in the inner loop.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Is it possible to check for new files without creating reference files, as they would require housekeeping as well.&lt;BR /&gt;&lt;BR /&gt;There's only one reference file created and we can easily remove it when done with a 'trap' statement.  In all the modified script looks like this:&lt;BR /&gt;&lt;BR /&gt;# cat ./watch&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;REFFILE=/tmp/REF.$$&lt;BR /&gt;trap 'rm -f ${REFFILE}' EXIT&lt;BR /&gt;touch ${REFFILE}&lt;BR /&gt;while true&lt;BR /&gt;do&lt;BR /&gt;    ls | while read FILE&lt;BR /&gt;    do&lt;BR /&gt;        [ ${FILE} -nt ${REFFILE} ] || continue&lt;BR /&gt;        awk 'NR&amp;gt;12 {exit 0};NR==12 &amp;amp;&amp;amp; /ABORT/ {print FILENAME":"$0;exit 0}' ${FILE}&lt;BR /&gt;    done&lt;BR /&gt;    touch ${REFFILE}&lt;BR /&gt;    sleep 600&lt;BR /&gt;done&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Wed, 06 Jan 2010 11:05:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558690#M678997</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-01-06T11:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: New to scripting, grateful for any help !!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558691#M678998</link>
      <description>Hi James,&lt;BR /&gt;&lt;BR /&gt;Thanks for your help, this may be a stupid question, but I'm assuming the REF file should contain a listing of what files have been read/checked. My question is, where/how do I define the directory that I need to check where all the files are held ?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Jeremy</description>
      <pubDate>Wed, 06 Jan 2010 13:44:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558691#M678998</guid>
      <dc:creator>Jeremy W</dc:creator>
      <dc:date>2010-01-06T13:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: New to scripting, grateful for any help !!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558692#M678999</link>
      <description>Hi (again) Jeremy:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; ...this may be a stupid question, but I'm assuming the REF file should contain a listing of what files have been read/checked. My question is, where/how do I define the directory that I need to check where all the files are held ?&lt;BR /&gt;&lt;BR /&gt;No, the 'REFFILE' is only used to create a mark-in-time (for you, every 5-minutes).  We use this to decide if a file is newer (more recently changed) since the last mark.&lt;BR /&gt;&lt;BR /&gt;If at sometime, t[n], a file meets the principal criteria of having the string "ABORT" somewhere on line-12, then we report the event.  Then, at some later time, t[n+m] another change to the file is made.  This triggers a re-examination of the file and a second report for the file.&lt;BR /&gt;&lt;BR /&gt;If this is _not_ what you want, there are ways to circumvent that.  You could filter the output through a 'sort -u' to reduce the results to unique entries.&lt;BR /&gt;&lt;BR /&gt;You could also store the name of any file meeting the match criteria in a hash (associative array in 'awk' parlance).  Then, skip repetitive output for any file once added to the hash.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 06 Jan 2010 14:04:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/new-to-scripting-grateful-for-any-help/m-p/4558692#M678999</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-01-06T14:04:36Z</dc:date>
    </item>
  </channel>
</rss>

