The Function node gives me 3 hostnames, how to loop easily to exec-command in each?

All is in the title :slight_smile:

Sadly still more information needed as there is literally an unlimited amount o ways how this 3 hostnames are “given”. How does the output-data of the node look like?

You are right jan
end of Function node :

items[0].json.myHosts = myHosts;
return items;

myHosts is type [:string]

Then it could look like this:

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "items[0].json.myHosts = ['google.com', 'microsoft.com'];\nreturn items;"
      },
      "name": "Mock Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        400,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return items[0].json.myHosts.map(host => {\n  return { json: {host} };\n})"
      },
      "name": "Split Hosts",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        600,
        300
      ]
    },
    {
      "parameters": {
        "executeOnce": false,
        "command": "=echo  {{$node[\"Split Hosts\"].json[\"host\"]}}"
      },
      "name": "Execute Command",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        800,
        300
      ]
    }
  ],
  "connections": {
    "Mock Data": {
      "main": [
        [
          {
            "node": "Split Hosts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Hosts": {
      "main": [
        [
          {
            "node": "Execute Command",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Yes, that works jan, so a single exec can launch several command sequentially or in parallel
But here I need to analyse the command result (stdout) on each host or partially, depending of previous host’s result, am I clear ?
In fact, a function where I could fork (promise for ex) is fine, but the Function node is not made for that I think … Or, give to Exec command a very long command with if, else etc… and get the final output for the nex node
Am I right ? An other way ?

Yes, that works jan, so a single exec can launch several command sequentially or in parallel

Yes

But here I need to analyse the command result (stdout) on each host or partially, depending of previous host’s result, am I clear ?

Sure, if you have to do that you can do that.

In fact, a function where I could fork (promise for ex) is fine, but the Function node is not made for that I think … Or, give to Exec command a very long command with if, else etc… and get the final output for the nex node

Not sure I understand. But it is possible to return a promise in the Function-Node. Apart from that, can you do literally anything in the Function-Node. You can even use any module that is installed as long as you configured n8n accordingly:
https://docs.n8n.io/reference/configuration.html#use-built-in-and-external-modules-in-function-nodes

If the code exists … jan do you have an example of a Function node usind the Exec-command node ?

That is not possible to use one node inside of another. What is possible is to use “child_process” in the Function-Node. Here the code of the Execute Command-Node:

or even simpler here some examples on stackoverflow:

Ok thanks jan!