On Tuesday 17 July 2007 12:05, McKown, John wrote:
>I'm looking for a __simple__ way to approach this. I would like to
>create a "log" type file from an application. Instead of logging to a
>specific file name each time, I would like to log to a "base name" which
>then appends an ever increasing number on the end. This is like a GDG in
>z/OS, where I just specify DSN=SOME.NAME(+1) and the system generates
>the next GDG number in sequence. So far, the best that I've come up with
>is something like:
A couple suggestions for efficiency:
- Use "ls -1" instead of "ls -l" to get just the filenames one-per-line.
- Use sed instead of awk to cut the numbers out.
- Suppress the error output from ls, in case there are no log files yet.
- Put the entire calculation of NEXT into one pipe:
# Get the number after the highest one used on an existing file:
NEXT=$(( $(ls -1 ${BASENAME}* 2>/dev/null | sed 's/.*\.//' | \
sort -nr | head -n1) + 1))
That takes advantage of the fact that $(( + 1)) evaluates to "1".
- MacK.
-----
Edmund R. MacKenty
Software Architect
Rocket Software, Inc.
Newton, MA USA
>#!/bin/sh
>cd /logging/sub/directory
>export BASENAME=base.name
>NEXT=$(ls -l ${BASENAME}.* | awk -F '.' '{print $NF}' | sort -nr | head
>-1)
>if [ -z $NEXT ]; then NEXT=0;fi
>NEXT=$((1+${NEXT}))
>export GDG=${BASEENAME}.${NEXT}
>program --logname=${GDG}
>
>
>--
>John McKown
>Senior Systems Programmer
>HealthMarkets
>Keeping the Promise of Affordable Coverage
>Administrative Services Group
>Information Technology
>
>The information contained in this e-mail message may be privileged
>and/or confidential. It is for intended addressee(s) only. If you are
>not the intended recipient, you are hereby notified that any disclosure,
>reproduction, distribution or other use of this communication is
>strictly prohibited and could, in certain circumstances, be a criminal
>offense. If you have received this e-mail in error, please notify the
>sender by reply and delete this message without copying or disclosing
>it.
>
>----------------------------------------------------------------------
>For LINUX-390 subscribe / signoff / archive access instructions,
>send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or
> visit http://www.marist.edu/htbin/wlvindex?LINUX-390
----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390