>>  I have the following code repeated for about 100
    >>  directories, and in each directory there are about
    >>  200 files:

    >> cd /directory
    >> for file in *
    >> do
    >>          if [ -f $file ] ; then
    >>          echo -e "From - `date +%c`" >> Misc
    >>          cat $file >> Misc
    >>          rm -f $file
    >>           echo "" > /tmp/.misc
    >> fi
    >> done

I think you'll find it will run faster if rewritten in another scripting
language, like Python or Perl.  Here's an untested Python transliteration of
what you wrote (you should have Python available on your RedHat system in
/usr/bin/python):

    import os, stat, time

    os.chdir("/directory")

    misc = open("Misc", "a")
    for file in os.listdir("."):
        mode = os.stat(file)[stat.ST_MODE]
        if stat.S_ISREG(mode):
            misc.write("From - %s\n" % time.strftime("%c",
                                                     time.localtime(time.time())))
            misc.write(open(file).read())
            os.unlink(file)
            open("/tmp/.misc", "w").write("\n")

If you want to stick with the Bourne shell, I would at least pull the date
command execution out of the loop.  It's unlikely the precise time of the
file's addition to your mailbox file is critical.  Also, I'm not sure what
the second echo command accomplishes.  Why not do it just once at the end?

    cd /directory
    from="From - `date +%c`"
    for file in *
    do
       if [ -f $file ] ; then
          (echo $from ; cat $file) >> Misc
          rm -f $file
       fi
    done
    echo "" > /tmp/.misc

or in Python:

    import os, stat, time

    os.chdir("/directory")

    misc = open("Misc", "a")
    from = "From - %s\n" % time.strftime("%c", time.localtime(time.time()))
    for file in os.listdir("."):
        mode = os.stat(file)[stat.ST_MODE]
        if stat.S_ISREG(mode):
            misc.write(from)
            misc.write(open(file).read())
            os.unlink(file)
    open("/tmp/.misc", "w").write("\n")

Skip Montanaro    | Musi-Cal: http://concerts.calendar.com/
[EMAIL PROTECTED] | Conference Calendar: http://conferences.calendar.com/
(518)372-5583


-- 
  PLEASE read the Red Hat FAQ, Tips, Errata and the MAILING LIST ARCHIVES!
http://www.redhat.com/RedHat-FAQ /RedHat-Errata /RedHat-Tips /mailing-lists
         To unsubscribe: mail [EMAIL PROTECTED] with 
                       "unsubscribe" as the Subject.

Reply via email to