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


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

The content are zipped files and names are basically dates.

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?


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": "",
    "stderr": ""

And the second node

    "code": 0,
    "signal": null,
    "stdout": "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\",
    "stderr": ""

Screenshot from the two nodes right and left:

It doesn’t really matter the content of the those zipped files, you can even do touch 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?


Hi @ansred, based on your screenshot it seems you are comparing a string like with a string that does not contain (instead your value 2 seems to look like 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.