Rule reference
A routing has two parts: General, with the scan and log options, and FileMatching, with the list of rules. In the database mode, the routing is maintained in the Riversoft® Console Portal and can be exported with -export. In the local file mode, it is a JSON file created from the example-config_rules.json template.
{
"General": { "Name": "INBOUND", "ScanDir": "/mailbox/IN", "LogLevelOnSuccess": 6, "LogLevelOnError": 1 },
"FileMatching": [
{
"Index": 0,
"Name": "NOTES",
"FileRegEx": "^NOTES.*\\.TXT$",
"General": { "SourceUser": "PARTNER", "WeekDayInterval": 127, "EndDateHour": 23, "EndDateMinute": 59, "EndDateSecond": 59 },
"Filename": { "RenameFileTo": "" },
"Copy": { "CopyToDir": "/mailbox/OUT", "CopyFileOption": 13 },
"Backup": { "BkpToDir": "/backup/notes", "BkpFileOption": 4 }
}
]
}Text fields accept regular expressions in RE2 syntax. Numeric fields marked as options are sums of values: to combine options, add the values, for example 1 + 4 + 8 = 13.
Routing General
| Field | Description |
|---|---|
Name, Description | Routing name and description. |
ScanDir | Scan directory. The -scan option takes precedence. |
ScanSubDir | 0: the directory only; 1: subdirectories only; 2: the directory and its subdirectories. The -nosubdir, -subdir and -subdir2 options take precedence. |
ScanDirRegEx, ScanDirRegExNeg | Expressions that include or exclude directories from the scan. |
ScanFileRegEx, ScanFileRegExNeg | Expressions that include or exclude files from the scan. |
ScanFirstRule | Number (Index) of the first rule evaluated. Default: 0. |
ScanLockSem | Name of the semaphore that prevents two simultaneous scans with the same name. |
ScanLockSemTimeout | Maximum wait for the semaphore, in milliseconds. -1 waits with no limit. |
ScanLockSemOptions | Options. 1: exits immediately if the semaphore is in use. |
LogErrorOption | Options. 1: records an error when the file cannot be read; 2: records an error when a directory cannot be read. |
LogLevelOnSuccess, LogLevelOnWarning, LogLevelOnInfo, LogLevelOnError | Level of the rule success, warning, information and error messages. Defaults: 6, 7, 7 and 1. See Message levels. |
ScanCheckFileInUse, DelayRetry, MaxRetries | Kept for compatibility. Not used in this version. |
File selection
Each FileMatching item is a rule. Rules are evaluated in Index order, and the first one that matches the file applies.
| Field | Description |
|---|---|
Index | Rule number, from 0, with no gaps. A gap ends the evaluation. |
Name, Description | Rule name and description. Available in $RULENAME and $DESCR. |
Locked | 1 locks the rule, which is then ignored. |
FileRegEx | Expression applied to the file name. |
DirRegEx | Expression applied to the file directory. |
SrcRegEx | Expression applied to the source given in -src. |
ContentRegEx | Expression applied to the first lines of the file. The number of lines is set in General.ContentLinesToRead. |
An empty field accepts any value.
Note
When ContentRegEx is filled in and the content does not match, processing of the file ends with an error, without evaluating the following rules. Use FileRegEx and DirRegEx to separate the files before checking the content.
Rule General
| Field | Description |
|---|---|
SourceUser, DestinationUser | Source and destination users associated with the rule. Available in $SRCUSER and $DSTUSER and used when recording messages. |
ExecProgBefore | Command run before the copy. |
ExecProg | Command run after the copy. |
ExecProgError | Command run when a step fails. |
CheckLockUnlockFileName | Control file checked before processing and removed at the end. Accepts variables. |
CreateLockUnlockFileName | Control file created during processing. Accepts variables. |
CheckLockUnlockOption | Control file options. See Control files. |
RemoveAfterCopy | 1 removes the original file at the end of processing. |
RemoveAfterHours | With RemoveAfterCopy, removes the original only if it is older than the given number of hours. 0: always removes it. |
ProcessAfterSeconds | Minimum age of the file, since its last modification, for it to be processed. The value is read in milliseconds. 0 disables it. |
InsertTimestamp | Options. 1: appends the date and time to the end of the name; 2: adds it to the start. The separator is .. |
InsertTimestampPart | Source of the date and time: 0, current time; 1, 2 or 3, file modification date. |
InsertTimestampFormat | Date and time format, written with the reference date 2006-01-02 15:04:05. Example: 20060102150405 produces YYYYMMDDhhmmss. Empty: YYYYMMDDhhmmss0mmm. |
DelayNextFileProcess | Pause after processing the file, in milliseconds. |
StartDateHour, StartDateMinute, StartDateSecond | Start of the allowed time. |
EndDateHour, EndDateMinute, EndDateSecond | End of the allowed time. |
WeekDayInterval | Allowed days: add 1 (Sunday), 2 (Monday), 4 (Tuesday), 8 (Wednesday), 16 (Thursday), 32 (Friday) and 64 (Saturday). 127 or 255: every day. |
FileLenOption | Options. 1: checks the minimum size; 2: checks the maximum size. |
FileLenMin, FileLenMax | Minimum and maximum sizes, in bytes. |
ReplaceFromFileOption | 1 enables building the name from the content (Filename.ReplacesFromFile). |
ContentLinesToRead | Number of lines read for ContentRegEx. |
OtherOption | Options. 2: resets the sequence number every day. |
NextSection | Name of the next rule to run on the same file. |
Overwrite | Kept for compatibility. To overwrite, use the Copy and Backup options. |
When the file is outside the allowed time, day, age or size, processing ends with a warning.
New name (Filename)
The new name is built in this order:
- Starts from
RenameFileTo. Empty: the new name starts empty and, if nothing is added, the original name is kept. - Applies
ReplacesFromFile, when enabled inReplaceFromFileOption. - Applies
Replaces, in order. - Adds the date and time, according to
InsertTimestamp. - Applies
ReplacesByRegEx, in order.
Replaces
Each item copies a piece from a source into the new name. Positions start at 1.
| Fields | Source of the piece |
|---|---|
ReplaceFileNamePosFrom, ReplaceFileNamePosTo, ReplaceFileNameLen | Original file name. |
ReplaceFileNameFromPathPosFrom, ReplaceFileNameFromPathPosTo, ReplaceFileNameFromPathLen | Original file directory. |
VarReplaceFileNamePosFrom, VarReplaceFileNamePosTo, VarReplaceFileNameLen, VarReplaceFileNameValue | Fixed value. The -var0 value replaces the first item’s value, -var1 the second item’s, and so on. |
InsertTimestampPosFrom, InsertTimestampPosTo, InsertTimestampLen | Date and time. |
InsertSeqNumberTo, InsertSeqNumberLen, InsertSeqNumberMin, InsertSeqNumberMax | Sequence number with leading zeros, from Min to Max, which returns to the minimum after the maximum. |
...PosFrom: start position of the piece in the source.0: start....PosTo: position in the new name where the piece is written, overwriting what is there.0or-1: appends to the end....Len: number of characters.0disables the item.
The last sequence number used is kept in the applLockDir directory. InsertSeqNumberSeq is kept for compatibility.
Example: for the file NF20261110.TXT, the item below produces 20261110, copying 8 characters from position 3:
{ "ReplaceFileNamePosFrom": 3, "ReplaceFileNamePosTo": -1, "ReplaceFileNameLen": 8 }ReplacesFromFile
Copies into the new name a piece of the first line of the file that matches the expression.
| Field | Description |
|---|---|
ReplaceFromFileRegEx | Expression that finds the line. |
ReplaceFromFilePosFrom, ReplaceFromFilePosTo, ReplaceFromFileLen | Piece of the line copied, with the same rules as Replaces. |
ReplaceFromFileNext | 1 keeps reading the following lines after finding this one. |
ReplacesByRegEx
Replaces in the new name each occurrence of RegExReplaceFrom with RegExReplaceTo. Use ${1}, ${2} for the groups and ${0} for the matched text. Example: "RegExReplaceFrom": "(?i)\\.txt$", "RegExReplaceTo": ".csv". RegExReplaceOcorr is kept for compatibility.
Copy (Copy)
| Field | Description |
|---|---|
CopyToDir | Destination directory. Empty: the original file directory. The -copydir option takes precedence. |
CopyFileOption | Copy options. See the table below. |
Replaces | Builds the destination directory by positions, as in Filename.Replaces, with the PathReplace... (original directory), PathReplaceFromFileName... (file name), PathInsertTimestamp... (date and time) and PathVarReplace... (fixed value or -var0 to -var9) fields. |
ReplacesByRegEx | Regular expression replacements in the destination directory. |
CopyTempExtension, CopyFileRecSize | Kept for compatibility. Not used in this version. |
| Value | CopyFileOption option |
|---|---|
1 | Performs the copy. Without this option, there is no copy. |
4 | Creates the destination directory if it does not exist. |
8 | Moves the file instead of copying it. |
16 | Overwrites the destination file. Without this option, the copy fails if the destination exists. |
64 | Inserts CR before each LF (Windows format). |
128 | Removes CR characters (Linux format). |
512 | Converts the new name to lowercase. |
1024 | Converts the new name to uppercase. |
Backup (Backup)
| Field | Description |
|---|---|
BkpToDir | Backup directory. The -backupdir option takes precedence. |
BkpFileOption | Backup options. 0: no backup. With any other value, the backup is made; also set BkpToDir. |
Replaces, ReplacesByRegEx | Build the backup directory, as in Copy. |
| Value | BkpFileOption option |
|---|---|
1 | Uses the new name in the backup. Without this option, uses the original name. |
4 | Creates the backup directory if it does not exist. |
16 | Overwrites the existing backup. |
32 | Makes the backup before the copy. Without this option, the backup is made after the copy. |
64, 128 | Inserts CR before LF or removes CR. |
256 | Appends the date and time to the end of the backup name. |
Control files
Control files signal to other processes that a file is being processed or is ready. The names accept variables, for example $PATHOLDNAME/$OLDNAME.lck.
| Value | CheckLockUnlockOption option |
|---|---|
2 | Before processing, requires CheckLockUnlockFileName to exist. |
4 | Before the ExecProgBefore command, creates CreateLockUnlockFileName. Fails if it already exists. |
8 | After the copy, creates CreateLockUnlockFileName. |
16 | At the end, removes CreateLockUnlockFileName. |
32 | At the end, removes CheckLockUnlockFileName. |
External commands
ExecProgBefore, ExecProg and ExecProgError receive a command with arguments, for example:
/usr/local/bin/notify.sh "$FILENEWNAME" $SRCUSER $DSTUSER- Variables are replaced before the run. See Variable reference.
- The command runs directly, without a shell: use the full path and, for redirections or pipes, call a script.
- Arguments in double or single quotes are passed without the quotes.
- Riversoft STCP Gemini Rename waits for the command to finish. An exit code other than
0is treated as a failure.