On Fri, 25 Sep 2009 17:31:01 -0500, Ward, Mike S wrote:

>Hello all, I'm kind of new to the OMVS world and I'd like a little help
>if possible. I have a directory in the OMVS segment that programs write
>their logs to.
>
This question is probably better asked on MVS-OE than on IBM-MAIN,
but I'll give it a try:

>How could I automate the ftping of those files to a windows ftp server
>for archive purposes then clear out the text file so that it can
>start fresh?
>
Suppose your transactions append their logs to "log.txt".  In your
crontab commands, call a script like:

# Create a second handle to the log:

    ln log.txt oldlog.txt ||
      { # somehow report error to process owner.  This most likely
        # happens because the previous day's log rotate failed, then:
        echo "rename of log failed" >&2
        exit 1;  }

# Create new log file and replace the active log file.
# Transactions which have opened the active log file will
# unknowingly continue to write to that file, now called
# oldlog.txt.  POSIX specification of mv guarantees tnat
# no starting transaction will fail to observe a log.txt:

    touch newlog.txt
    mv newlog.txt log.txt

# Wait long enough for transactions in progress to complete.
# Ugh.  Timing dependent.  There may be a better way.  Then
# FTP to Windows server; delete if successful:

    sleep 1000
    echo 'put oldlog.txt windows.log.txt
          quit' |
    ftp windows-server '(exit' ||
      { # Somehow report error to process owner, then.
        echo "ftp of log failed" >&2
        exit 1;  }

    rm oldlog.txt
    exit 0

If two transactions run concurrently, their records will appear
interleaved in the log file.  This can be avoided by either:

o Each transaction's buffering its log records and writing all
  to the log with a single call to write(), or

o Prefixing each record with a unique transaction ID and later
  sorting on that field,

or some combination of both.

This script should write nothing to stdout, and write to stderr
only if errors occur.  Crontab mails the combined content of
stdout and stderr to the process owner, but not if both are
empty.  So you'll get email notification of failure but not
of success.  If you want notification of success, add an
echo command before the "exit 0".

-- gil

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html

Reply via email to