procmail
[Top] [All Lists]

Re: how to deliver to a file with a unique time-stamped file name, reliably?

2005-01-19 08:04:23
On Wed, 19 Jan 2005, Robert Allerstorfer wrote:

On Tue, 18 Jan 2005, 16:36 GMT-08 Gary Funck wrote:

Not bad, but how do we make sure that the file named by $MYDATE
isn't overwritten by another process executing this script within
the same second in time?

Hi,

in my SoftlabsAV package, I am creating an unique ID number for each
mail, including the mail's processing date and time with an accurancy
of at least to the second. That ID will be in the format
"YYYYMMDD-hhmmss.xxxxxx" where the x's are either 6-digits
microseconds (if supported by the OS), or 5-digits Process-ID:

 av_ID
 :0
  {
     # Creating an unique mail ID number, based on the current time. For
     # this, we call 'date' (only once in the entire recipe, so this
     #   should not cause a significant performance decrease).
     #   We want the ID to be in the format "YYYYMMDD-hhmmss.xxxxxx"
     av_ID = `date +"%Y%m%d-%H%M%S.%N"`
     # eg. "20041203-163017.405974000" or "20041203-163017.N"
     # If %N (nanoseconds) has been supported, strip its last 3 digits
     #    (probably only zeros); otherwise use the 5-digits PID

     :0
      * av_ID ?? ^^\/........-......\.......
      {
         av_ID = $MATCH
         # eg. "20041203-163017.405974"
         #                      ^^^^^^
         #                      6-digits microseconds
      }

     :0 E
      {


        What will you do if the subject is "HaloDear-Sancho.Pancho"?

        I think that job ID is better because it's short and you
        can follow the logs in case of problem.

MYDATE=`date '+%y%m%d%H%M%S'`.$$

        It will be uniq.

Bye,
 Udi

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>