Rename Rules


If not specified otherwise in "$AFD_WORK_DIR/etc/AFD_CONFIG, then in the file "$AFD_WORK_DIR/etc/rename.rule" all rules on how to rename a file are listed. This file is automatically read again when the date of the file has been changed. There are three different options in the DIR_CONFIG file which can use the rename.rule: rename, trans_rename, file name is user, file name is target, mail header, attach file, attach all files and subject. The first one is explained as an example below:

[directory]
/the/directory/where/the/files/come/in

   [files]
   *

      [destination]

         [recipient]
         ftp://recipient_1:password@hostname/destination/directory

         [options]
         lock OFF
         rename rule_1
         priority 5

         [recipient]
         ftp://recipient_2:password@hostname/destination/directory

         [options]
         lock DOT
         rename rule_2
         priority 2

In file "$AFD_WORK_DIR/etc/rename.rule" these two rules must be defined:

[rule_1]
abc*.*     new_filename*.new.*.test
*123*      *new_filename*

[rule_2]
*          file.dat

NOTE: The rules must always start on the beginning of a new line ie. there may not be any spaces in front. The rule header (in the example above rule_1), may be up to 80 characters (MAX_RULE_HEADER_LENGTH) long.

The result of these entries would be that all files for recipient_2 would be renamed to file.dat. For recipient_1 the file abcdef.txt would renamed to new_filenamedef.new.txt.test and file AB123CD.txt would be renamed to ABnew_filenameCD.txt.



Features of the rename rule

Feature Description Example Rule Result for file abcde
* and ? You can use the same '*' and '?' in the rename rule.
??*   ?-?-*                
a-b-cde
%*n and %?n To address a specific * or ?.
??*   %?2-*-%?1            
b-cde-a
%on and %On-m To address a specific character or character range. There are two special characters: ^ for the first character and $ for the last character.
*     %o1-%o2-%O3-$        
a-b-cde
%tx Insert the actual time in any form. The character x determines the time format which can be one of the following:
            a - short day "Tue",           A - long day "Tuesday",
            b - short month "Jan",         B - long month "January",
            d - day of month [01,31],      m - month [01,12],
            j - day of the year [001,366], y - year [01,99],
            Y - year 1997,                 R - Sunday week number [00,53],
            w - weekday [0=Sunday,6],      W - Monday week number [00,53],
            H - hour [00,23],              M - minute [00,59],
            S - second [00,60]
            U - Unix time, number of seconds since 00:00:00 01/01/1970 UTC
       
*     %ta-*-%tA            
Mon-abcde-Monday
%T[+|-|*|/|%]xS|M|H|d Time modifier for the above %tx option. It adds (+), subtracts (-), multiplies (*), divides (/) or computes the modulo (%) with the value x to the current unix time. The default unit for the time modifier is seconds this can be changed to minute (M), hour (H) or day (d). Once set the modifier is used for all subsequent %t until it changed by the next modifier as shown in the example.
*     *.%td_%T+1d%td_%T0%td
abcde.28_29_28
%n Insert a unique number four characters long.
*     *.%n                 
abcde.286f
%ab Insert an alternating number toggling between 0 and 1. With this you can do load balancing by always sending files with a 0 to one host and the ones with the 1 to another host.
*     *_%ab                
abcde_1
%adx Insert an alternating decimal number toggling between 0 and x. x must be a decimal number and may not be larger then 9. This enables load balancing between up to 10 hosts.
*     *_%ad4               
abcde_3
%ahx Insert an alternating hexadecimal number toggling between 0 and x. x must be a hexadecimal number and may not be larger then f. This enables load balancing between up to 16 hosts.
*     *_%ahd               
abcde_a
%h Insert the hostname of the current node. Depending on how the system is configured, this might return full network node hostname.
*     *.%h                 
abcde.ducktown.money.dw
%H Some as above, only that this cuts away the domain. So it will just deliver the hostname.
*     *.%H                 
abcde.ducktown
%% Insert a %.
*     *%                   
abcde%
\ End of a number.
*     %o1\234              
a234


Copyright © 1997 - 2023 by H.Kiehl
Holger.Kiehl@dwd.de
Last updated: 24.01.2023
[red dot]Index [red dot]Home