Remove Line Feed from passing into variables.
Posted: Thu Mar 02, 2017 5:21 pm
Good Afternoon All,
I am trying to read a flat file. The contents of the flat file look like the following:
/opt/local/GoAnywhere_Services/userdata/workspace/1000000023197
/opt/local/GoAnywhere_Services/userdata/workspace/1000000022986
/opt/local/GoAnywhere_Services/userdata/workspace/1000000022985
/opt/local/GoAnywhere_Services/userdata/workspace/1000000023195
/opt/local/GoAnywhere_Services/userdata/workspace/1000000022981
/opt/local/GoAnywhere_Services/userdata/workspace/1000000023198
/opt/local/GoAnywhere_Services/userdata/workspace/1000000023200
I am then using a for-each loop, and setting up a variable:
<setVariable name="folders" value="${folder[1]}${system.carriageReturn}" version="2.0" />
I am then setting up the command structure that I am trying to accomplish. This command will go out and delete the folders that were provide in the flatfile:
<setVariable label="SetVar: Cmd" name="Cmd" value="rmdir "${folders}"" version="2.0" />
<print label="Create Command File" file="${system.job.workspace}/CrtDelete.sh" append="false" version="1.0">
<![CDATA[${Cmd}]]>
</print>
<exec label="Make Command Executable" executable="chmod" workingDir="${system.job.workspace}" version="1.0">
<arg value="+x" />
<arg value="${system.job.workspace}/CrtDelete.sh" />
</exec>
<exec label="Delete Empty Directory" executable="${system.job.workspace}/CrtDelete.sh" workingDir="${system.job.workspace}" version="1.0" logLevel="debug" />
</forEachLoop>
The problem I am having is that the variable is adding a bunch of spaces or a line feed and it is adding a \r to the end of the folder name, which is causing the script to fail saying that is not a valid folder.
How can I get the file to read each line separately to feed the folder names?
Here the the logs:
3/2/17 4:12:13 PM INFO Data parsed successfully and the rowset variable 'folder_list' was created
3/2/17 4:12:13 PM INFO Finished task 'readFlatFile 1.0'
3/2/17 4:12:13 PM INFO Entering loop 'forEachLoop'
3/2/17 4:12:13 PM INFO Opening file '/opt/local/GoAnywhere_Services/userdata/webdocs/Z6AAB/FolderList'
3/2/17 4:12:13 PM INFO Executing task 'setVariable 2.0'
3/2/17 4:12:13 PM INFO Variable 'folders' was created and set to '/opt/local/GoAnywhere_Services/userdata/workspace/1000000023197
'.
3/2/17 4:12:13 PM INFO Finished task 'setVariable 2.0'
3/2/17 4:12:13 PM INFO Executing task 'setVariable 2.0 (SetVar: Cmd)'
3/2/17 4:12:13 PM INFO Variable 'Cmd' was created and set to 'rmdir "/opt/local/GoAnywhere_Services/userdata/workspace/1000000023197
"'.
3/2/17 4:12:13 PM INFO Finished task 'setVariable 2.0 (SetVar: Cmd)'
3/2/17 4:12:13 PM INFO Executing task 'print 1.0 (Create Command File)'
3/2/17 4:12:13 PM INFO Finished task 'print 1.0 (Create Command File)'
3/2/17 4:12:13 PM INFO Executing task 'exec 1.0 (Make Command Executable)'
3/2/17 4:12:13 PM INFO Preparing to execute the native command 'chmod' with the argument(s) '+x, /opt/local/GoAnywhere_Services/userdata/workspace/1000000023210/CrtDelete.sh'
3/2/17 4:12:14 PM INFO The native command 'chmod' finished with a return code of '0'
3/2/17 4:12:14 PM INFO Finished task 'exec 1.0 (Make Command Executable)'
3/2/17 4:12:14 PM INFO Executing task 'exec 1.0 (Delete Empty Directory)'
3/2/17 4:12:14 PM INFO Preparing to execute the native command '/opt/local/GoAnywhere_Services/userdata/workspace/1000000023210/CrtDelete.sh'
3/2/17 4:12:14 PM INFO rmdir: failed to remove `/opt/local/GoAnywhere_Services/userdata/workspace/1000000023197\r': No such file or directory
3/2/17 4:12:15 PM INFO The native command '/opt/local/GoAnywhere_Services/userdata/workspace/1000000023210/CrtDelete.sh' finished with a return code of '1'
3/2/17 4:12:15 PM ERROR [9003 - exec] The executable encountered an error with a return code of '1'. To ignore this error, set the attribute 'errorIfExecutableFails' to false. Full stack trace written to '1000000023210_error_1.log'
3/2/17 4:12:15 PM INFO Continuing with the next task or module, if any
3/2/17 4:12:15 PM INFO Executing task 'setVariable 2.0'
3/2/17 4:12:15 PM WARN Variable 'folders' was replaced with '/opt/local/GoAnywhere_Services/userdata/workspace/1000000022986
'.
3/2/17 4:12:15 PM INFO Finished task 'setVariable 2.0'
3/2/17 4:12:15 PM INFO Executing task 'setVariable 2.0 (SetVar: Cmd)'
3/2/17 4:12:15 PM WARN Variable 'Cmd' was replaced with 'rmdir "/opt/local/GoAnywhere_Services/userdata/workspace/1000000022986
"'.
I am trying to read a flat file. The contents of the flat file look like the following:
/opt/local/GoAnywhere_Services/userdata/workspace/1000000023197
/opt/local/GoAnywhere_Services/userdata/workspace/1000000022986
/opt/local/GoAnywhere_Services/userdata/workspace/1000000022985
/opt/local/GoAnywhere_Services/userdata/workspace/1000000023195
/opt/local/GoAnywhere_Services/userdata/workspace/1000000022981
/opt/local/GoAnywhere_Services/userdata/workspace/1000000023198
/opt/local/GoAnywhere_Services/userdata/workspace/1000000023200
I am then using a for-each loop, and setting up a variable:
<setVariable name="folders" value="${folder[1]}${system.carriageReturn}" version="2.0" />
I am then setting up the command structure that I am trying to accomplish. This command will go out and delete the folders that were provide in the flatfile:
<setVariable label="SetVar: Cmd" name="Cmd" value="rmdir "${folders}"" version="2.0" />
<print label="Create Command File" file="${system.job.workspace}/CrtDelete.sh" append="false" version="1.0">
<![CDATA[${Cmd}]]>
</print>
<exec label="Make Command Executable" executable="chmod" workingDir="${system.job.workspace}" version="1.0">
<arg value="+x" />
<arg value="${system.job.workspace}/CrtDelete.sh" />
</exec>
<exec label="Delete Empty Directory" executable="${system.job.workspace}/CrtDelete.sh" workingDir="${system.job.workspace}" version="1.0" logLevel="debug" />
</forEachLoop>
The problem I am having is that the variable is adding a bunch of spaces or a line feed and it is adding a \r to the end of the folder name, which is causing the script to fail saying that is not a valid folder.
How can I get the file to read each line separately to feed the folder names?
Here the the logs:
3/2/17 4:12:13 PM INFO Data parsed successfully and the rowset variable 'folder_list' was created
3/2/17 4:12:13 PM INFO Finished task 'readFlatFile 1.0'
3/2/17 4:12:13 PM INFO Entering loop 'forEachLoop'
3/2/17 4:12:13 PM INFO Opening file '/opt/local/GoAnywhere_Services/userdata/webdocs/Z6AAB/FolderList'
3/2/17 4:12:13 PM INFO Executing task 'setVariable 2.0'
3/2/17 4:12:13 PM INFO Variable 'folders' was created and set to '/opt/local/GoAnywhere_Services/userdata/workspace/1000000023197
'.
3/2/17 4:12:13 PM INFO Finished task 'setVariable 2.0'
3/2/17 4:12:13 PM INFO Executing task 'setVariable 2.0 (SetVar: Cmd)'
3/2/17 4:12:13 PM INFO Variable 'Cmd' was created and set to 'rmdir "/opt/local/GoAnywhere_Services/userdata/workspace/1000000023197
"'.
3/2/17 4:12:13 PM INFO Finished task 'setVariable 2.0 (SetVar: Cmd)'
3/2/17 4:12:13 PM INFO Executing task 'print 1.0 (Create Command File)'
3/2/17 4:12:13 PM INFO Finished task 'print 1.0 (Create Command File)'
3/2/17 4:12:13 PM INFO Executing task 'exec 1.0 (Make Command Executable)'
3/2/17 4:12:13 PM INFO Preparing to execute the native command 'chmod' with the argument(s) '+x, /opt/local/GoAnywhere_Services/userdata/workspace/1000000023210/CrtDelete.sh'
3/2/17 4:12:14 PM INFO The native command 'chmod' finished with a return code of '0'
3/2/17 4:12:14 PM INFO Finished task 'exec 1.0 (Make Command Executable)'
3/2/17 4:12:14 PM INFO Executing task 'exec 1.0 (Delete Empty Directory)'
3/2/17 4:12:14 PM INFO Preparing to execute the native command '/opt/local/GoAnywhere_Services/userdata/workspace/1000000023210/CrtDelete.sh'
3/2/17 4:12:14 PM INFO rmdir: failed to remove `/opt/local/GoAnywhere_Services/userdata/workspace/1000000023197\r': No such file or directory
3/2/17 4:12:15 PM INFO The native command '/opt/local/GoAnywhere_Services/userdata/workspace/1000000023210/CrtDelete.sh' finished with a return code of '1'
3/2/17 4:12:15 PM ERROR [9003 - exec] The executable encountered an error with a return code of '1'. To ignore this error, set the attribute 'errorIfExecutableFails' to false. Full stack trace written to '1000000023210_error_1.log'
3/2/17 4:12:15 PM INFO Continuing with the next task or module, if any
3/2/17 4:12:15 PM INFO Executing task 'setVariable 2.0'
3/2/17 4:12:15 PM WARN Variable 'folders' was replaced with '/opt/local/GoAnywhere_Services/userdata/workspace/1000000022986
'.
3/2/17 4:12:15 PM INFO Finished task 'setVariable 2.0'
3/2/17 4:12:15 PM INFO Executing task 'setVariable 2.0 (SetVar: Cmd)'
3/2/17 4:12:15 PM WARN Variable 'Cmd' was replaced with 'rmdir "/opt/local/GoAnywhere_Services/userdata/workspace/1000000022986
"'.