Signiant Support

Sample Filename Mapping Command using dds_perl Print


Scenario


You want to change the name of the transferred files 'in transit' without modifying the file names on the source agent.

Discussion

The Filename Mapping Commands can be used to accomplish this.  Your template can be configured to use a Filename Mapping Command on the source agent, the target agent or both agents. 
 
Which command to use (source or target) depends on what information you need to perform the name mapping.  For example, if you want to check for the existence of a file with the same name on the target and change the name of the transfered file before it is written, you would use the Target Filename Mapping command as it will be able to query the file system of the target agent.
 
As a version of Perl (dds_perl) is shipped with every agent, using dds_perl will ensure that the mapping commands will run regardless of agent platform, be it Windows, Unix, Mac OS X or Linux. 

Example

The following is an example Target Filename Mapping Command which will check if the file already exists on the target and rename it.  It will append an integeter to the original file name and increment the integer until a unique name is found.
        #!dds_perl
        # Target Filename Mapping Command
   
        select STDOUT; $| = 1;
        select STDERR; $| = 1;
   
        my $FILENAME;
        my $TYPE;
        my $SKIPFILE = "*** skip ***";
        my $newFileName;
        my $count = 0;
        while (<STDIN>)
        {
            #
            # use implicit $_ from <STDIN>
            # $1 should have file name and $2 should have src_host
            #
        
            m/\"(.+)?\"\s+(\S+)?\s+(\S+)?\s+(\S+)?\s+/;
        
            $FILENAME = $1;
            $TYPE = $4;
            $target = '';
            $ffound = 0;
   
            # change '\' to '/', need a uniform separator
            $FILENAME =~ s/\\/\//g;
 
            $newFileName = $FILENAME;
 
            if ( $TYPE == "F" ) {
                # only concerned about Files, not Directories or Links
                $count = 0;
                while ( -e $newFileName ) {
                    #Does the file exist?  If so, pick a new name based on $count
                    $count++;
                    $newFileName = $FILENAME . '_' . $count;
                }
    
                print STDOUT "$newFileName\n";
                $count++;
            }
        }
 
        exit 0;


The above is an example only, and a trivial one at that. You will want to modify it for robustness and enhance it for your particular task.