Configure a Job Action that Executes a Command

Job actions are triggered when Reflection Gateway detects new or updated files in a scanned directory. Use this procedure to invoke a command action. You can configure commands that run once or specify a command to act on each file that met the scan conditions.

NOTE:The command runs as a remote SSH command executed using the user account specified for UserID on the New/Edit SFTP Server page. The executable file and output locations must be available to this user. The working directory is the SSH terminal login directory for that user.

To configure a Job action that executes a command

  1. Create a Job and specify the scan server and directory.

  2. On the New Job (or Edit Job) page, under Actions, from the Add action... list, select Execute command.

    This opens the Execute Command dialog box.

  3. For Options, select one of the following:

    • Run once executes the command a single time.

    • Run for each file executes the command for each file that has been added or updated since the last scan.

  4. For Server, select the SFTP server on which this command will run.

  5. For Command, specify the command to run and any arguments you want to pass to this command. See Sample Commands for Job Actions below for examples.

    • The command runs as a remote SSH command executed using the user account specified for UserID on the SFTP server setup page. The executable file and output locations must be available to this user. The working directory is the user’s home directory.

    • On Windows servers, precede DOS commands with cmd /c, for example:

      cmd /c echo $FILENAME$ >> c:\output\filelist.txt

    • If you include full path information for output, as shown in the example above, the directories in the specified path must exist, and the user who is specified for UserID in the file server definition must have access to these directories.

    • If you do not include full path information for command output, it is created in the terminal session login directory for the user who is specified for UserID in the file server definition. On UNIX systems this is typically the home directory (home/userID). On the Reflection for Secure IT Server for Windows, this is the user’s Windows Profile directory by default (c:\users\userID). This default can be modified from the Reflection for Secure IT Server console using the Permissions pane.

  6. Click OK to close the Execute Command dialog box.

  7. Click Save.

  8. Click Run Now to test the Job. (If this is a repeat test, first update the files in the source location.)

Sample Commands for Job Actions

Use these examples as models for testing and configuring Jobs that execute commands. Samples include appropriate syntax for both Windows and UNIX servers.

Example 1: Run Once

This example uses the echo system command and the $RELATIVE_FILE_LIST$ token to send a list files on the scanned server that meet the criteria for the Job.

  • Options is set to Run once

  • Server can be the scanned server or a destination server. In this example, the output file (filelist.txt) is created in a directory called output in the root directory of the selected server. The user account specified for authenticating to this server must have write access to this directory.

Windows SFTP server

Command: cmd /c echo $RELATIVE_FILE_LIST$ >> c:\output\filelist.txt

UNIX SFTP server

Command: echo $RELATIVE_FILE_LIST$ >> /output/filelist.txt

Example 2: Run for each file

This example use a script to create a text file that lists token values for each transferred file. The action runs on the destination server after a transfer Job action has copied files to this server.

  • Files have been transferred to a directory called upload in the root directory of the destination server. The script is in a directory called script on the same server, and output of the script is created in the script directory. The user account specified for this SFTP server must have write access to both upload and script.

  • Options is set to Run for each file

  • Server is set to the destination server name.

  • File tokens are passed to the script as command line arguments. Because the returned values of these tokens can include spaces and special characters, the arguments are enclosed in double quotes.

Windows SFTP server

c:\script\tokenoutput.bat "$FILENAME$" "$FULL_PATH$" "$RELATIVE_FILE_NAME$"

Contents of tokenoutput.bat:

echo FILENAME:      %1 >> c:\script\tokenvalues.txt
echo FULL_PATH:     %2 >> c:\script\tokenvalues.txt
echo RELATIVE PATH: %3 >> c:\script\tokenvalues.txt
echo ================= >> c:\script\tokenvalues.txt

UNIX SFTP server

/script/tokenoutput.sh "$FILENAME$" "$FULL_PATH$" "$RELATIVE_FILE_NAME$"

Contents of tokenoutput.sh:

echo FILENAME:      $1 >> /script/tokenvalues.txt
echo FULL_PATH:     $2 >> /script/tokenvalues.txt
echo RELATIVE PATH: $3 >> /script/tokenvalues.txt
echo ================= >> /script/tokenvalues.txt

NOTE:The script file must have execute permissions set. For example:

chmod +x tokenoutput.sh