Parsing Juniper CLI Output

Describe the problem/error/question

I need to extract a list of connected subscribers from a Juniper network router via SSH. We would also like to eliminate the “cd /” from the executed command as it is not supported on this device.

##Example output:
error: unknown command: cd\npp0.3221370504 149.102.21.133 [email protected] default:default \npp0.3221370506 149.102.9.136 [email protected] default:default \npp0.3221370520 149.102.9.146 [email protected] default:default \npp0.3221370524 149.102.9.147 [email protected] default:default \npp0.3221370539 149.102.9.174 [email protected] default:default

Please share your workflow

image

Share the output returned by the last node

error: unknown command: cd\npp0.3221370891 149.102.12.100 [email protected] default:default \npp0.3221370893 149.102.22.120 [email protected] default:default \npp0.3221370895 149.102.22.121 [email protected] default:default \npp0.3221370896 149.102.22.122 [email protected] default:default \npp0.3221370899 149.102.12.205 [email protected] default:default \n---(more 60%)---

What we would like to extract:

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

With the above desired output, the first portion before the @ sign is a variable length string between 6 and 12 digits long.

Information on your n8n setup

  • n8n version: 0.222.3
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): [Unsure]
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • Operating system: Ubuntu 22.04 LTS

Hi @Robert_Fitzgerald, welcome to the community!

Based on the example you have provided it sounds like you can:

  1. Split your string by line
  2. Remove the line starting with error:
  3. Split each line on the whitespaces and keep the third result for each line

This is a bit tricky but possible. Here’s an example workflow:

In this example I’ve kept the respective input line for comparison, but if you want to get rid of it simply flip the “Keep Only Set” toggle on the node:

Hope this helps!

Thanks so much for the great solution, I copied/pasted from your example however I’m struggling to get the last node to work correctly with keeping the 3rd item, are you able to see what’s wrong? It should be identical to yours, although I did have to re-create the “Split into separate items” as it showed up unrecognised when I pasted it.

Here’s what I have now:

This is the output showing my side from the above flow:

I suspect this could be related to the exact data structure you are having. Can you confirm the exact JSON output your SSH node returns? Please make sure to copy it like so to not loose any formatting:

Thanks Tom, really appreciate you taking the time to help me :slight_smile:

[
{
"code":
0,
"signal":
null,
"stdout":
"error: unknown command: cd pp0.3221373588 149.102.10.150 [email protected] default:default pp0.3221373590 149.102.10.177 [email protected] default:default pp0.3221373592 149.102.19.167 [email protected] default:default pp0.3221373606 149.102.19.179 [email protected] default:default pp0.3221373608 149.102.19.180 [email protected] default:default ---(more 100%)---",
"stderr":
""
}
]

Hi @Robert_Fitzgerald, this looks like you might have selected your JSON code and then copied it instead of using that Copy button.

Could you try copying this data one more time? Make sure you use the button highlighted in my screenshot, it’ll only appear once you hover over the actual JSON payload:

)

You should get your JSON payload with indentation when copying it as described above.

1 Like

Sorry Tom, it shows me 3 options for copying on that button, the last response I used Copy Item Path, here are the others:

Copy Selection and Copy Parameter Path didn’t seem to do anything at all (even with text selected), is there another way to achieve it?

I’m so sorry for this, this UI has changed a bit recently. On your version of n8n you’d need to click on the first line of your JSON data here, then use the Copy Selection option, I’ve explained this over here with another screenshot.

Ultimately this would come down to finding a split logic that works for your exact data structure.

1 Like

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