Post Action Script
Using Post Action Script is not recommended. If you plan to use post action script, please contact OPSWAT Technical Support to see if there are different ways of achieving the same goal. For example, if you want to copy files after scan, use the Workflow - copy to directory feature instead.
Running scripts on clean/infected files
Creating a post action script provides the capability to handle simple or advanced application logic. Once a file is scanned by engines, the script will be executed on a file based on scan results.
XML format for post action script
<
post_action
>
<
scripts
>
<
if
type
=
"[scan result]"
>[script]</
if
>
…
<
if
type
=
"[scan result]"
>[script]</
if
>
</
scripts
>
<
user_vars
>
<
user_var
name
=
"[user variable]"
>[user variable string]</
user_var
>
…
<
user_var
name
=
"[user variable]"
>[user variable string]</
user_var
>
</
user_vars
>
</
post_action
>
Item |
Description |
Example |
[script] |
Batch script supported by cmd.exe. For multiline scripts,use “&&”. (“&&” for xml) |
DEL c:\eicar.com |
[scan result] |
Refer to asynchronous scan API in Software Developer Guide |
for clean files, 0 |
[user variable] |
Variables that you define |
data_folder |
[user variable string] |
Value for user variables |
C:\ data_folder_for_archiving |
Pre-defined variables
Variables |
Description |
Note |
%%%file_path%%% |
Absolute path to the file to be scanned. |
This variable is supported only on local COM scans. |
%%%threat_name%%% |
Name of threats found by engines. |
Applies only to infected(“1”) scan result. |
%%%scan_finished%%% |
The time when scan is finished. |
|
Applying post action script
Property Name |
post_action |
Description |
XML-formatted scripts applied per scan result with support of pre-defined variables and user-defined variables. |
CLI |
omsCmdLineUtil.exe config pa=<xml file path> |
Management Console |
On the Metadefender Core Management Console, use only the script in the text box, instead of the XML format for Post Action Script described in the above section. |
Remark |
Any character that has special meaning to XML (e.g., &, <, >) must be escaped. |
Example of post action script XML
Note: In the following examples, any variable surrounded with %%% that is not already defined in pre-defined variables, need to either be defined in your post action XML or replaced with the actual values you intend to use.
Moving clean file and infected files to different folder
<
post_action
>
<
scripts
>
<
if
type
=
"0"
>move %%%file_path%%% c:\archive_data\clean</
if
>
<
if
type
=
"1"
>move %%%file_path%%% c:\archive_data\infected</
if
>
</
scripts
>
</
post_action
>
Uploading infected file to ftp server
<
post_action
>
<
scripts
>
<
if
type
=
"1"
>
echo OPEN %%%server%%%> ftp.scr&&
echo %%%username%%%>> ftp.scr&&
echo %%%password%%%>> ftp.scr&&
echo cd test_post_action>> ftp.scr&&
echo put %%%file_path%%%>> ftp.scr&&
echo CLOSE>> ftp.scr&&
echo quit>> ftp.scr &&
ftp -s:ftp.scr
</
if
>
</
scripts
>
<
user_vars
>
<
user_var
name
=
"server"
>127.0.0.1</
user_var
>
<
user_var
name
=
"username"
>ftp_user</
user_var
>
<
user_var
name
=
"password"
>1234abcd</
user_var
>
</
user_vars
>
</
post_action
>