Command Task Examples
This page provides examples of Command Tasks that can be used to automate file management, logging, and testing actions during transfer processing.
These examples use supported Replacement Variables, such as ${FILE_PATH}, and demonstrate typical commands for Linux and Windows environments.
Usage Notes
When configuring a Command Task, keep the following in mind:
- Ensure that the command is valid for the operating system where UDMG Server is running.
- Verify that the user account running UDMG Server has the necessary permissions to execute the command and access the referenced paths.
- When using Replacement Variables, ensure that values are quoted appropriately, especially when file paths may contain spaces.
Replacement Variables are expanded by UDMG before the command is executed. They are not operating system environment variables. Use the placeholder syntax ${VARIABLE_NAME} on both Linux and Windows.
File Management Operations
Rename the File
Description: Renames the processed file by appending .processed to the filename.
Recommended Event Types:
- On Sent
- On Received
- On Error
Command:
- Linux
- Windows (CMD)
mv "${FILE_PATH}" "${FILE_PATH}.processed"
cmd /c rename "${FILE_PATH}" "${FILE_NAME}.processed"
Delete the File
Description: Deletes the file after processing.
Recommended Event Types:
- On Sent
- On Received
- On Error
Command:
- Linux
- Windows (CMD)
rm -f "${FILE_PATH}"
cmd /c del /Q "${FILE_PATH}"
Compress the File
Description: Compresses the file after transfer.
Recommended Event Types:
- On Sent
- On Received
Command:
- Linux
- Windows (PowerShell)
gzip -f "${FILE_PATH}"
This example creates an archive of the file without removing the original. Please invoke a custom script to perform both actions if the removal is required.
powershell.exe -Command "Compress-Archive -Path '${FILE_PATH}' -DestinationPath '${FILE_PATH}.zip' -Force"
Move the File to Another Directory
Description: Moves the file to a different directory on the host system.
Recommended Event Types:
- On Sent
- On Received
Command:
- Linux
- Windows (CMD)
mv "${FILE_PATH}" "/tmp/processed/"
cmd /c move "${FILE_PATH}" "C:\Temp\processed"
Create a Copy of the File
Description: Creates a backup copy of the file without modifying the original.
Recommended Event Types:
- On Sent
- On Received
Command:
- Linux
- Windows (CMD)
cp "${FILE_PATH}" "${FILE_PATH}.bak"
cmd /c copy "${FILE_PATH}" "${FILE_PATH}.bak"
Logging
Write Transfer Metadata to a Log File
Description: Writes transfer-related metadata to a log file using replacement variables.
Recommended Event Types:
- On Sent
- On Received
- On Error
Command:
- Linux
- Windows (CMD)
sh -c 'echo "User=${ACCOUNT_USERNAME}, Protocol=${PROTOCOL}, File=${FILE_PATH}" >> /tmp/transfer.log'
cmd /c echo User=${ACCOUNT_USERNAME}, Protocol=${PROTOCOL}, File=${FILE_PATH}>> "C:\Temp\transfer.log"
Testing
Fail Intentionally
Description: Executes a command that fails, which can be used to test error handling and Task execution behavior.
Recommended Event Type:
- On Error
Command:
- Linux
- Windows (CMD)
ls /nonexistent_directory
cmd /c dir "C:\nonexistent_directory"