<?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: Scripting issue in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149396#M683501</link>
    <description>Here's a solution that doesn't use sed/awk:&lt;BR /&gt;&lt;BR /&gt;egrep "REMOVE" HOUSEKEEP_FILES | while read DIR FILE ACTION DAYS_OLD ; do&lt;BR /&gt;   [[ $DAYS_OLD -gt 2 ]] &amp;amp;&amp;amp;  find $DIR -name "$FILE" -print&lt;BR /&gt;done</description>
    <pubDate>Thu, 08 Jan 2009 15:48:22 GMT</pubDate>
    <dc:creator>Autocross.US</dc:creator>
    <dc:date>2009-01-08T15:48:22Z</dc:date>
    <item>
      <title>Scripting issue</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149395#M683500</link>
      <description>&lt;!--!*#--&gt;
&lt;P&gt;Hi All&lt;BR /&gt;&lt;BR /&gt;I am attempting to create a quick and simple skulker script. This is what I intended.&lt;BR /&gt;&lt;BR /&gt;A text file containing some thing similar to&lt;BR /&gt;cat HOUSEKEEP_FILES&lt;BR /&gt;-------------------------------------------------------------&lt;BR /&gt;FileSys Strin ACTION DAYS OLD&lt;BR /&gt;-------------------------------------------------------------&lt;BR /&gt;/tmp/martin/1 file1001 REMOVE 2&lt;BR /&gt;/tmp/martin/1 file1002 REMOVE 2&lt;BR /&gt;/tmp/martin/1 file1003 REMOVE 2&lt;BR /&gt;/tmp/martin/2 file1004 REMOVE 3&lt;BR /&gt;/tmp/martin/2 file1005 REMOVE 3&lt;BR /&gt;/tmp/martin/2 file1006 REMOVE 3&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I wanted to use a sed and awk command, lets say to fin files older than 2 or 3 ($4) in the directory ($1) the actual file ($2). I dont think I'm to far away bu reading that but the command blurps. By the way I am just trying to list initially. The command I am using is,&lt;BR /&gt;&lt;BR /&gt;sed -n '/REMOVE/p' HOUSEKEEP_FILES | awk '{system(find $1, " " -name $2," " -print)}'&lt;BR /&gt;&lt;BR /&gt;is there any awk gurus who can simplify this?&lt;BR /&gt;&lt;BR /&gt;thanks very much&lt;BR /&gt;&lt;BR /&gt;Martin&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S. this thread has been moved from HP-UX &amp;gt;&amp;nbsp;System Administration to HP-UX &amp;gt; languages - HP Forums Moderator&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2012 02:55:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149395#M683500</guid>
      <dc:creator>Dadski</dc:creator>
      <dc:date>2012-11-27T02:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149396#M683501</link>
      <description>Here's a solution that doesn't use sed/awk:&lt;BR /&gt;&lt;BR /&gt;egrep "REMOVE" HOUSEKEEP_FILES | while read DIR FILE ACTION DAYS_OLD ; do&lt;BR /&gt;   [[ $DAYS_OLD -gt 2 ]] &amp;amp;&amp;amp;  find $DIR -name "$FILE" -print&lt;BR /&gt;done</description>
      <pubDate>Thu, 08 Jan 2009 15:48:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149396#M683501</guid>
      <dc:creator>Autocross.US</dc:creator>
      <dc:date>2009-01-08T15:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149397#M683502</link>
      <description>&lt;!--!*#--&gt;Looks a bit dangerous. For each line, you're about to remove potentially several files.&lt;BR /&gt;&lt;BR /&gt;For example, when receiving the first non-header line of HOUSEKEEP_FILES, your script would not remove only: &lt;BR /&gt;/tmp/martin/1/file1001 &lt;BR /&gt;&lt;BR /&gt;but also anything matching: &lt;BR /&gt;/tmp/martin/1/*/file1001&lt;BR /&gt;/tmp/martin/1/*/*/file1001&lt;BR /&gt;/tmp/martin/1/*/*/*/file1001&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;(When creating automated file removers, you *must* be as specific and predictable as possible. The hard way of learning this lesson involves restoring files from backups and restarting long-running processing jobs while thinking about how to explain this to an angry customer :-)&lt;BR /&gt;&lt;BR /&gt;If the directory structure is predictable, it would be much safer to directly assemble the name of the file to be removed instead of fishing around with the find command.&lt;BR /&gt;&lt;BR /&gt;If the file paths are of the form "/FileSys/Strin", then you could do something like this:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;grep '^/.*REMOVE' HOUSEKEEP_FILES | \&lt;BR /&gt;while read FileSys Strin junk; do&lt;BR /&gt;    echo "rm \"$FileSys/$Strin\""&lt;BR /&gt;    # rm "$FileSys/$Strin" # uncomment after testing&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;The first grep command passes through only the lines beginning with a '/' character, so we get rid of all the header lines. After that it's just a matter of reading each line, collecting the columns to variables and assembling the necessary command line.&lt;BR /&gt;&lt;BR /&gt;Of course, the above approach is slow and causes excessive forking of new processes.&lt;BR /&gt;So, here's version 2:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;grep '^/.*REMOVE' HOUSEKEEP_FILES | \&lt;BR /&gt;  awk '{ print $1 "/" $2 };' | \&lt;BR /&gt;    xargs echo rm&lt;BR /&gt;# Replace "xargs echo rm" with "xargs rm" if OK&lt;BR /&gt;&lt;BR /&gt;Note that there is no loop at all, just a single pipeline. You could even write it as a one-liner, but I think it's easier to understand when written on multiple lines.&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Thu, 08 Jan 2009 16:17:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149397#M683502</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2009-01-08T16:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149398#M683503</link>
      <description>be aware that the above solutions do not address the "age" of the file.  And you've not defined what you mean by age.  There are access times and modification times, but "creation" time is not available (unless the file is absolutely never touched after creation)</description>
      <pubDate>Thu, 08 Jan 2009 16:27:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149398#M683503</guid>
      <dc:creator>OldSchool</dc:creator>
      <dc:date>2009-01-08T16:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149399#M683504</link>
      <description>&lt;!--!*#--&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;Hmm, lot of possibilities.&lt;BR /&gt;&lt;BR /&gt;I was even thinking about generalizing the&lt;BR /&gt;script. What if HOUSEKEEP_FILES could contain&lt;BR /&gt;different keywords in the third column (not only "REMOVE"). For example:&lt;BR /&gt;&lt;BR /&gt;-------------------------------------------------------------&lt;BR /&gt;FileSys         Strin           ACTION          DAYS OLD&lt;BR /&gt;-------------------------------------------------------------&lt;BR /&gt;/tmp/martin/1   file1001        REMOVE          2&lt;BR /&gt;/tmp/martin/1   file1002        REMOVE          2&lt;BR /&gt;/tmp/martin/1   file1003        REMOVE          2&lt;BR /&gt;/tmp/martin/2   file1004        REMOVE          3&lt;BR /&gt;/tmp/martin/2   file1005        KEEP            3&lt;BR /&gt;/tmp/martin/2   file1006        REMOVE          3&lt;BR /&gt;&lt;BR /&gt;Here is my little script:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;awk '! /---|DAYS OLD/ {print}' HOUSEKEEP_FILES | while read SEARCHDIR FILE ACTION HOWOLD&lt;BR /&gt;do&lt;BR /&gt;   case $ACTION in&lt;BR /&gt;      REMOVE|remove) ACTION="rm -f" ;;&lt;BR /&gt;      *)             ACTION="ll" ;;&lt;BR /&gt;   esac&lt;BR /&gt;   find $SEARCHDIR -name $FILE -type f -mtime $HOWOLD -exec $ACTION {} \;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;And here is what it would run:&lt;BR /&gt;&lt;BR /&gt;find /tmp/martin/1 -name file1001 -type f -mtime 2 -exec rm -f {} \;&lt;BR /&gt;find /tmp/martin/1 -name file1002 -type f -mtime 2 -exec rm -f {} \;&lt;BR /&gt;find /tmp/martin/1 -name file1003 -type f -mtime 2 -exec rm -f {} \;&lt;BR /&gt;find /tmp/martin/2 -name file1004 -type f -mtime 3 -exec rm -f {} \;&lt;BR /&gt;find /tmp/martin/2 -name file1005 -type f -mtime 3 -exec ll {} \;&lt;BR /&gt;find /tmp/martin/2 -name file1006 -type f -mtime 3 -exec rm -f {} \;&lt;BR /&gt;&lt;BR /&gt;I am sure there are many more ways to&lt;BR /&gt;do it :)&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;VK2COT</description>
      <pubDate>Thu, 08 Jan 2009 16:31:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149399#M683504</guid>
      <dc:creator>VK2COT</dc:creator>
      <dc:date>2009-01-08T16:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149400#M683505</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;it is not clear, in which way you want to use the file name.&lt;BR /&gt;I suggest, that if there is no value of 'fil' found in awk, use any filespec found in the list. Else use only the specified filespec.&lt;BR /&gt;&lt;BR /&gt;Wrap my awk in a script of your choice;&lt;BR /&gt;start with something like this in the commandline to test your expectations:&lt;BR /&gt;&lt;BR /&gt;#filespec=file1002 # may be set&lt;BR /&gt;awk -v age=3 -v dir=/tmp/martin/1 -v fil="$filespec" 'NR&amp;lt;4 {next}&lt;BR /&gt;($3 == "REMOVE") &amp;amp;&amp;amp; ($4 &amp;gt;= age) &amp;amp;&amp;amp; ($1 == dir) { if(fil &amp;amp;&amp;amp; $2 != fil) next&lt;BR /&gt;sys_str="find "dir" -type f -name "$2" -mtime +"age" -print"&lt;BR /&gt;print sys_str&lt;BR /&gt;system(sys_str)}' HOUSEKEEP_FILES&lt;BR /&gt;&lt;BR /&gt;You could implement the handling of directory names the same way as I did with the filespec.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;mfG Peter&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 08 Jan 2009 16:36:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149400#M683505</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2009-01-08T16:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149401#M683506</link>
      <description>Thanks all for replying VK2COT  you've nailed it, thats exactly what I was looking for.  thanks  to all.</description>
      <pubDate>Fri, 09 Jan 2009 07:38:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149401#M683506</guid>
      <dc:creator>Dadski</dc:creator>
      <dc:date>2009-01-09T07:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149402#M683507</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;nice, that we could help you!&lt;BR /&gt;Because you are new to this forum - Welcome! - I want to put yout attention to its unique point system:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums11.itrc.hp.com/service/forums/helptips.do?#33" target="_blank"&gt;http://forums11.itrc.hp.com/service/forums/helptips.do?#33&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;mfG Peter&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 09 Jan 2009 11:12:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149402#M683507</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2009-01-09T11:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting issue</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149403#M683508</link>
      <description>Just a note - we have a similar script.&lt;BR /&gt;&lt;BR /&gt;We use ZIP as an option too. So 2 day old logs get zipped, then deleted after 7 days.&lt;BR /&gt;&lt;BR /&gt;So you would have:&lt;BR /&gt;/tmp/martin/1   file1001   ZIP        2&lt;BR /&gt;/tmp/martin/1   file1001   REMOVE     7&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 09 Jan 2009 11:41:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-issue/m-p/5149403#M683508</guid>
      <dc:creator>Mark McDonald_2</dc:creator>
      <dc:date>2009-01-09T11:41:48Z</dc:date>
    </item>
  </channel>
</rss>

