Trying to get comfortable with the exec node and getting tripped up a bit.
I wish to open an SSH session to another server to execute commands.
In the exec node I can set the "command" to
and then I found that I can inject a payload that includes semicolon separated commands like
cd ../; pwd; echo "hello world"
And this all works as expected, but I would like to better understand a few things...
If instead of semicolons I try passing the above commands on separate lines, I get
bash: line 0: cd: too many arguments
I guessed that semicolons are simply required for interactive terminal and if I want the script to run non-interactively I can add
#!/bin/bash at the beginning... this appears to run (return code 0), but nothing is output. Is that just how it is with a non-interactive script?
I think I may want to be able to read the output to a command and then send another command conditionally. Can I keep the ssh session open so that I can pass additional commands without losing context?
As you can probably tell I'm a beginner in the differences between interactive terminal and scripts, so any hints you can offer would be helpful!
The exec node will just execute one command line, so yes you can combine command using ; onto one line - and you can use | to pipe to output the result of one command into the next - or && to only carry out the next command if the previous one passes. This is all operating system dependent of course as it's just the operating system that is executing the command.
If you want to leave a session open then maybe look at the node-red-node-daemon node instead as that is designed to run long running commands and provides an input to send in data and provides the results as they appear.
Recently I tested "EXEC" node with a simple ping 127.0.0.1 and ping 127.0.0.0 to get a ping value that was good and one that is not. I ran the command on Windows and get an output on the 3rd output "return code" being Code 0 or Code 1 as I had expected with a summary of the error.
I tried it on my Linux Mint laptop at home and I discovered that when it was using ping 127.0.0.1 it has no output. I do get a resopnse of Code 2 with the ping 127.0.0.0.... Why does Linux have a difference of output code, If the ping command actually works?
Is it because the ping syntax I'm using is perpetual? as in Windows Ping 127.0.0.1 -t. is similar to just a simple ping 127.0.0.1.... maybe that's it.
I also noted that the output when set to "when the command is complete", and it gets an error when "ping 127.0.0.0" is sent, it gives 3 outputs, the first is a "Good", with the color being blue, and then followed by message that says it "failed". It is apparent that the Linux version of the "Exec" seems buggy.
If you have an issue please start another thread rather than take this one off topic.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.