HP3000-L Archives

April 2003, Week 4

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Jeff Woods <[log in to unmask]>
Reply To:
Jeff Woods <[log in to unmask]>
Date:
Mon, 21 Apr 2003 22:33:04 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (112 lines)
Hi, "e.e." donna.  ;)

At -0700 01:23 PM 4/21/2003, Donna Garverick wrote:
>      39   :  run main.pub.vesoft;&
>      40   :    info="purge
>./logs/access_log.@(credate<today-30);yes"
>      41
>      43   -----Purging
>/APACHE/PUB/logs/access_log.20030222231354900 (16 sectors)
>      44   -----Purging
>/APACHE/PUB/logs/access_log.20030301231746900 (32 sectors)

>is there a shell-ish way of doing the same thing i'm doing with mpex?

Of course!  Some ways that come to mind:

1. Simplest(?) solution, but may fail if the command buffer overflows due
to many matching files and/or long paths:
$ rm $(find ./logs -name 'access_log.*' -ctime +30)

2. For *each* matching file, print the path and then invoke rm to delete it:
$ find ./logs -name 'access_log.*' -ctime +30 -print  -exec rm {} \;

3. For *each* matching file, echo a prettier message and then delete it:
$ find ./logs -name 'access_log.*' -ctime +30 -exec echo Deleting: {} \;
-exec rm {} \;

4. Pipe filenames to xargs which will prevent buffer overflow by invoking
rm (only) as many times as needed:
$ find ./logs -name 'access_log.*' -ctime +30 |xargs rm

5. Same flaws as example 1, but otherwise does the same as example 3 in an
easier to read manner:
$ for Z in $(find ./logs -name 'access_log.*' -ctime +30)
 > do
 > echo Deleting: ${Z}
 > rm ${Z}
 > done

I'd probably use example 4, but 3 and 5 both have merit too.  All the
examples invoke "find" only once, but only example 1 invokes "rm" just
once.  All the other examples invoke "rm" (and where present "echo") once
for each file.  Example 4 invokes "xargs" once and "rm" as few times as
feasible (probably just once) passing multiple filenames to each invocation.

Note the "invoke" above means "fork and exec", which means "create a new
process".  Unless you know the number of files will be small and/or you
don't care about performance issues, examples 2, 3 and 5 may be ill-advised.

I haven't tested most of these so there may be typos or other flaws.  I
suggest you experiment with the above replacing "rm" with "echo would
remove" or "echo ls -ldc" to see what happens.

Some note re: the examples:

The single-quote ['] surrounds literal text to prevent the shell command
line from trying to do parameter substitution or "file globbing" (aka
"pattern matching") so that the wild-carded filename is passed intact to
"find".

The $(...) construct is analogous to `...` but is preferable due in part to
being able to be nested as needed.  Similarly, the ${Z} construct is
preferable to a "naked" $Z

The "for", "do" and "done" commands are shell built-ins.

The "-exec" option to "find invokes a command on each matching file at that
point in the find command-list.  If the return value from the executed
command is not zero, then "find" disqualifies the file.  So in example 2,
moving "-print" to the end would only print file names that "rm" succeeded
in deleting, but not files where "rm" failed.  Also note that in an "-exec"
phrase "{}" is replaced with the path to the file and the phrase *must* be
terminated with a ";" which *also* must be "escaped" with a leading
backslash (i.e. "\;") to prevent the shell from splitting the command at
that point.

I'm not sure whether you prefer to use "-ctime" or "-mtime" or "-atime" or
one (or more) of the other filters available in "find".  You may also want
to check +30 to see if +29 might be more directly analogous to your MPEX
selection.  And if "find" on MPE/iX supports "-daystart" you may want to
add that.  For more info on "find" do a "man find" in the shell.  :)

Since this example is very similar to my favorite list of  "most useful"
Unix command-line tools that I find myself frequently using and
recommending, I'll list them here and where you may find them documented:

find
$ man find

for/file globbing/parameter (and other) substitution/etc.
$ man sh

grep/fgrep/egrep
$ man grep

basic regular expressions/extended regular expressions
$ man regexp

Of course, there are many, many other very useful things... ranging from
the mundane to the exotic..  To borrow a slogan from Nissan a few years
back:  Enjoy the ride!  :)

--
Jeff Woods <[log in to unmask]>

In the beginning was The Word
and The Word was Content-type: text/plain
         -- author unknown

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2