Skip to content

Remove Line Feed from passing into variables.

Post any question you may have in regards to GoAnywhere MFT and let our talented support staff and other users assist you.
If you need a quicker response, please create a support ticket via the customer portal my.goanywhere.com or contact our support team by email at [email protected].
  • abarry1 Offline
  • Posts: 4
  • Joined: Fri Feb 17, 2017 11:02 am

Remove Line Feed from passing into variables.

Post by abarry1 »

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
"'.
  • Support_Rick Offline
  • Support Specialist
  • Posts: 590
  • Joined: Tue Jul 17, 2012 2:12 pm
  • Location: Phoenix, AZ
  • Contact:

Re: Remove Line Feed from passing into variables.

Post by Support_Rick »

ABarry1,

Check out the following link in the forums ... I believe it will give you the information you're looking for, as well as a project to help you accomplish what you're trying to do.

Working with Folder Variables

Utilizing this utility, you then have can read the "rowset" (of folder variables) then delete the desired folders with the "delete" task.
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
  • abarry1 Offline
  • Posts: 4
  • Joined: Fri Feb 17, 2017 11:02 am

Re: Remove Line Feed from passing into variables.

Post by abarry1 »

Rick,

Thanks. That is actually the project that I have been working with. I was just having an issue with the line feed causing the problem. I just added a search and replace on the file to remove the line feed and I was able to get it working with no problems.

Thanks for your reply.

Adam
Post Reply