Executing a Script
To execute a script
1. In My webMethods: Administration > Integration > Managed File Transfer > Event Management.
3. Click the tab containing the event for which you are creating the file operation action (Post-Processing Events or Scheduled Events).
4. Select the event in the event list.
5. In the Actions section, click the Select Action list.
6. In the resulting dialog box, click the Select Category list, select Execute Script, and then click OK.
7. In the Source Filter box, enter the name of the file whose transfer will trigger this event. By default, ActiveTransfer Server considers all files.
Note: You can use wildcard characters to filter the file names. For example, enter *.zip to trigger the event only when zip files are uploaded or downloaded. To trigger an event based on a name string in the zip files, use the name string in the Source Filter box, preceded and followed by wildcard characters. For example, enter *invoice*.zip to trigger the event based on the file URLs, when zip files containing the character string invoice in their file names are uploaded or downloaded. If you define a Source Filter for an action, the action acts only on the files that are filtered out.
For information on the use of wildcards in
ActiveTransfer Server, see
Use of Special Characters in Search.
8. If you want to use regular expression in the source filter, specify a valid regular expression in Source Filter and select Use regular expression.
Examples for regular expressions:
(.(?!purchaseorder))* | Excludes files with the file URL containing purchaseorder |
.*/out/.* | Include files with the file URL containing the folder out |
^abc(.*)123$ | Includes anything that starts with abc and ends with 123. Matches abc123, abcxyz123, but not abcxyz123def |
NEW-((*.doc)|(*_backup_*)) | Includes anything starting with NEW- that either ends in .doc, or is followed by the string _backup_ |
9. In the Command box, type a command. Keep in mind that running a batch (.bat) file requires running cmd.exe at a command prompt and passing it the arguments to execute the batch file.
10. In the Arguments box, type the command’s arguments. For example, enter {real_path}/archive/{name}:. If the file is uploaded to /uploads/stuff.zip, it will be copied to /archive/stuff.zip.
Note: The execution of the script takes place in the underlying operating system and cannot be controlled by ActiveTransfer. So, ensure that the script handles the sanitization of the arguments (especially the file name) that are passed to the script to avoid or mitigate security risks.
11. In the Separator box, type a regular expression to separator arguments.
12. In the Working Directory box, type the path to the directory where the command will execute. For example, when an application looks for a resource such as a configuration file, the application looks in the location specified here.
Important: Make sure the path ends with “/” to identify the location as a folder and not a file.
You should configure the Execute Script action settings depending on your operating system. One example each for the Windows and Unix/Linux platforms are listed below:
Windows Platform: If you want to execute the batch file
C:\SAG\batchfiles\test.bat, the properties that you need to specify for the Execute Script action are:
Command C:\Windows\System32\cmd.exe
Argument /c;start;test.bat
Separator ;
Working Directory C:\SAG\batchfiles\
Unix/Linux Platforms: You can directly specify the script file name. If you want to execute the batch file
/home/data/batchfiles/test.sh, use the following settings in the Execute Script action.
Command /bin/bash
Argument test.sh;arg1;arg2
Separator ;
Working Directory /home/data/batchfiles
The above configuration settings can vary depending on the specific operating system that hosts your ActiveTransfer Server. In some of the operating systems, you might require an exit command at the end of the script file to properly terminate the command process.
13. If you want to execute an error action if the file operation fails, select Execute error action.
14. Click Save.
15. If you selected the Execute error action check box, define an error action as described in Defining an Error Action. 16. If you are finished defining actions for this event, activate the event as described in Activating an Event. Result:
The “Execute a Script” action runs a script for each file in the list that is passed on to the action by the previous action. The script should be available in the same location as the files. The script is run on the machine on which ActiveTransfer is installed. The “Execute a Script” action waits for the script to complete execution before passing on the control to the next action. The script that is executed as part of this action should include an exit command so that the execution control is transferred back to ActiveTransfer. This action does not modify the list of files from the previous action.