Issue - IF Node - Not working as expected when check matching content between two directories

Greetings,

Trying to do match content between content of two linux direcotries.

The content are zipped files and names are basically dates.

Example:
SSH Linux # 1
cd /tmp/temp-illumio/BACKUPS/zipped && ls -p | grep -v /

SSH Linux #2
cd /volume1/Anas/Projects/illumio/PCE/SNC/BACKUP/n8n && ls -p | grep -v /

Using IF node to say (Equal) doesn’t work, maybe because Equal works with numbers not files?
So I tired at least to do (Contains) still doesn’t work

As you can see from the screenshot, the IF node output both true and false, which is incorrect, because it has to be one result.

Any idea what is wrong here or maybe if there a better way to do it?

Maybe doing two SFTP nodes and use LIST content of both to check is better? Will the IF node work with content between two SFTP nodes?

Thanks

Hi @ansred, this looks unexpected indeed. Can you share the JSON data you are passing on from the SSH node to your IF node and also the IF node itself so I can reproduce the problem you are seeing?

Thanks for looking in this @MutedJam

Here is the JSON

Hey @ansred, sorry for the misunderstanding, I meant the actual data, not the workflow (as I can’t run these SSH commands anyway) :slight_smile:

You can copy it like so:

Recording 2022-12-29 at 12.54.10

Thank you!

Sorry I missed that, @MutedJam

So basically, it’s running via SSH this command to list the names of the files:

cd /tmp/temp-illumio/BACKUPS/zipped && ls -p | grep -v /

Output would be from the first node

[
  {
    "code": 0,
    "signal": null,
    "stdout": "24-12-2022.zip",
    "stderr": ""
  }
]

And the second node

[
  {
    "code": 0,
    "signal": null,
    "stdout": "01-09-2022.zip\n01-10-2022.zip\n01-11-2022.zip\n01-12-2022.zip\n02-09-2022.zip\n02-10-2022.zip\n02-11-2022.zip\n02-12-2022.zip\n03-09-2022.zip\n03-10-2022.zip\n03-11-2022.zip\n03-12-2022.zip\n04-09-2022.zip\n04-10-2022.zip\n04-12-2022.zip\n05-09-2022.zip\n05-10-2022.zip\n05-11-2022.zip\n05-12-2022.zip\n06-09-2022.zip\n06-10-2022.zip\n06-11-2022.zip\n06-12-2022.zip\n07-08-2022.zip\n07-09-2022.zip\n07-10-2022.zip\n07-11-2022.zip\n08-08-2022.zip\n08-09-2022.zip\n08-10-2022.zip\n08-11-2022.zip\n09-08-2022.zip\n09-09-2022.zip\n09-10-2022.zip\n09-11-2022.zip\n10-08-2022.zip\n10-09-2022.zip\n10-10-2022.zip\n10-11-2022.zip\n10-12-2022.zip\n11-08-2022.zip\n11-09-2022.zip\n11-10-2022.zip\n11-11-2022.zip\n12-08-2022.zip\n12-09-2022.zip\n12-10-2022.zip\n12-11-2022.zip\n13-08-2022.zip\n13-09-2022.zip\n13-10-2022.zip\n13-11-2022.zip\n14-08-2022.zip\n14-09-2022.zip\n14-10-2022.zip\n14-11-2022.zip\n15-08-2022.zip\n15-09-2022.zip\n15-10-2022.zip\n15-11-2022.zip\n16-08-2022.zip\n16-09-2022.zip\n16-10-2022.zip\n16-11-2022.zip\n17-08-2022.zip\n17-09-2022.zip\n17-10-2022.zip\n17-11-2022.zip\n18-08-2022.zip\n18-09-2022.zip\n18-10-2022.zip\n18-11-2022.zip\n19-08-2022.zip\n19-09-2022.zip\n19-10-2022.zip\n19-11-2022.zip\n20-08-2022.zip\n20-09-2022.zip\n20-10-2022.zip\n20-11-2022.zip\n21-08-2022.zip\n21-09-2022.zip\n21-10-2022.zip\n21-11-2022.zip\n22-08-2022.zip\n22-09-2022.zip\n22-10-2022.zip\n22-11-2022.zip\n23-09-2022.zip\n23-10-2022.zip\n23-11-2022.zip\n24-09-2022.zip\n24-10-2022.zip\n24-11-2022.zip\n24-12-2022.zip\n25-08-2022.zip\n25-09-2022.zip\n25-10-2022.zip\n25-11-2022.zip\n26-08-2022.zip\n26-09-2022.zip\n26-10-2022.zip\n26-11-2022.zip\n27-08-2022.zip\n27-09-2022.zip\n27-10-2022.zip\n27-11-2022.zip\n28-08-2022.zip\n28-10-2022.zip\n28-11-2022.zip\n29-08-2022.zip\n29-09-2022.zip\n29-10-2022.zip\n29-11-2022.zip\n30-08-2022.zip\n30-09-2022.zip\n30-10-2022.zip\n30-11-2022.zip\n31-08-2022.zip\n31-10-2022.zip",
    "stderr": ""
  }
]

Screenshot from the two nodes right and left:

Note:
It doesn’t really matter the content of the those zipped files, you can even do touch 24-12-2022.zip and so on, as long the naming is matching.

Hope that helps, please let me know if you have any other questions.

Thanks so much @ansred! I now had a closer look at this and it seems you have the “Always Output Data” switch enabled on the IF node:

This would cause n8n to always return an (empty) item on the first output of a node and appears to be what’s causing the problem here. Perhaps you might want to just disable this option?

1 Like

You got it right @MutedJam ! It validates now one of the options which is should be the expected action.

Maybe that should be added to the IF node guide page? as a note for other users

However, the result as you can see from the screenshot

It shows as FALSE, even though as you can see from the stdout from both nodes contains the node A and B.


So, it should be True.

Or maybe the contains condition in the IF node is a bit more sensitive and should use regex maybe?

If yes, do you have a regex to match node A stdout whatever it there with stdout node B?

Thanks

Hi @ansred, based on your screenshot it seems you are comparing a string like 24-12-2022.zip 31.12.2022.zip with a string that does not contain 24-12-2022.zip 31.12.2022.zip (instead your value 2 seems to look like ...24-12-2022.zip 25-0-.2022.zip...). So the comparison is working fine here.

Perhaps you want to run your comparison individually for each file you are getting from SSH - PCE - LIST - PHASE#3, like so?

I am using .split() here to split up your SSH - PCE - LIST - PHASE#3 results into individual items, then mix them with the full result from SSH - DSM - LIST - PHASE#3 to apply the IF logic.

Yes, it seems to be sensitive the IF condition on the type of output. It would be nice though to have a custom regex, with that it would work with any specified format.

Update: I used your workaround to split the filenames. Actually that is a good idea and It seems to be working!

Thanks for all the help @MutedJam . Really appreciated!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.