LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Running Command Line Prompts through LabVIEW

Hello everyone!

 

I am looking to control a router through some LabVIEW prompts so that I might be able to automate it's configuration. The router supports configuration via ssh-ing into it through command line prompts. So I was planning on using LabVIEW's system exec VI to run commands to a command line window that will control the router through ssh. That being said, in order to access the router through ssh, you need to be able to login to the router (give a password when prompted after a command is issues on the command line). As I'm a rookie with using the system exec VI, I wanted to ask a few questions to be sure this is feasible before wasting too much time on this approach. 

 

1. Is it possible to enter multiple commands, one after the other into the same command prompt window through labview's system exec VI, or any other VI? I see that this VI can run commands, I just want to ensure that it can execute multiple commands in a row. 

 

2. Is it possible to enter information when prompted, as described above, through LabVIEW? This is what I am more concerned about.

 

I would really appreciate any input anyone might have from experience in this area! If you would like any additional information, I would be more than happy to provide that. My apologies if these questions are elementary.

0 Kudos
Message 1 of 6
(1,523 Views)

@alexm1 wrote:

Hello everyone!

 

I am looking to control a router through some LabVIEW prompts so that I might be able to automate it's configuration. The router supports configuration via ssh-ing into it through command line prompts. So I was planning on using LabVIEW's system exec VI to run commands to a command line window that will control the router through ssh. That being said, in order to access the router through ssh, you need to be able to login to the router (give a password when prompted after a command is issues on the command line). As I'm a rookie with using the system exec VI, I wanted to ask a few questions to be sure this is feasible before wasting too much time on this approach. 

 

1. Is it possible to enter multiple commands, one after the other into the same command prompt window through labview's system exec VI, or any other VI? I see that this VI can run commands, I just want to ensure that it can execute multiple commands in a row. 

 

2. Is it possible to enter information when prompted, as described above, through LabVIEW? This is what I am more concerned about.

 

I would really appreciate any input anyone might have from experience in this area! If you would like any additional information, I would be more than happy to provide that. My apologies if these questions are elementary.


Eeew, yuck.  I've done this before and it's not fun!  Well, actually it was a little bit fun.  If there's a com port option, it might be better to get the console that way because then you won't have to do coding acrobatics to keep an ssh session alive.  If your command structure is organized as a command tree, you will have to figure out a way to get all the way back to the root so you can navigate the tree to the command the same way all the time.  I think you'll also have to find a way to use multiple characters as an EOL so you can tell when a response ends.

If anyone has a better way to do this, please chime in.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 6
(1,514 Views)

Well since your device has an SSH interface the logical way to do that would be to use an SSH library of VIs. Now implementing SSH in LabVIEW is pretty much a no-go. Not so much that it would be impossible but it's not practical. The first S in SSH stands for secure and that means automatically cryptography. And there is a saying in cryptography: "Badly implemented cryptography is much worse than no cryptography at all!"

 

Implementing cryptographic algorithms is hard, first you need to understand all the math behind it, then you need to translate it into the programming language and finally you need to test it, and test it again, and test even more!!! And last but not least you need to have other experts in cryptography review your code over and over again to be reasonably sure that you haven't created an obfuscator rather than a cryptography solution. This makes an implementation in LabVIEW pretty unfeasible, even if you could do the whole programming and testing, you will be hard pressured to find cryptography experts who understand LabVIEW good enough to be able to review your code. Besides cryptography requires low level bit shuffling and all that stuff and LabVIEW as high level programming language isn't ideal for that sort of things. A LabVIEW implemented solution will always be somewhat slower than one implemented in C or a similar language (this doesn't apply for all programming problems, but cryptography falls into that group).

 

Now you can of course go and venture into getting libssh.dll interfaced to LabVIEW. It's doable but a lot of low level work. Or you could go and investigate .Net SSH libraries. Slightly easier if you aren't feeling totally at home with C compilers and how to call DLLs but still not trivial. There are various libraries out there from people who tried this and usually the ones that are more than just a thrown together bunch of VIs that seem to work if you cross your fingers, tap 5 times on the table while doing a rain dance and then don't touch the beast anymore, will be not free.

 

One of the libraries that is for quite some time on the market and still maintained would be https://lvs-tools.co.uk/software/encryption-compendium-labview-library/. Yes it costs money but if you need encryption it is worth that money. It uses OpenSSL for most of the encryption stuff and libSSH for the SSH client implementation.

 

Another approach would be to use redirection through pipes in which you call putty over pipes so that its standard IO is directly redirected to stream channels that you can read and write as strings. There exist a few potential solutions. My OpenG Pipe library was never released, but there are also libraries using .Net for this. They all work, when they work, and when they don't, well bad luck for you. Pipes, while a very prominent and often used feature under Unix, never quite made it on Windows to anything but some geeky low level feature.

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 6
(1,472 Views)

The SystemExec.vi is not interactive. That is, you provide a path, a command, a StandardInput. Then, the command is executed, and when it's done, you get the output.

With OpenSSH, a command line like

 

ssh pi@raspberrypi 'cat /proc/cpuinfo; exit'

would open a connection to the target and execute the commands. Note that exit is very important, since labview waits until the entire command is done.

Now, SSH seems to clear the standard input cache before it asks for the password, so you can't pass it there.

 

If you always connect to the same device, ssh-agent may be a solution. Basically, you enter a password on your machine once, and won't need to enter a password when opening ssh connections to the device any more.

0 Kudos
Message 4 of 6
(1,438 Views)

Thanks everyone for the advice! I ended up using plink on windows, which you can specify a password, set it to non-interactive, and feed in a txt file with commands to run on the router. The full command I used was:

plink username@IP -batch -pw YourPassword -m “C:\Your file location.txt”

 

In plink:

-batch specifies to remove the interactive part of plink requiring you to press return after signing in

-pw allows you to enter your password in the command

-m allows you to specify the location of a text file that contains all of the commands that you want to run once you’ve entered ssh.

 

Hope this helps someone else in the future! I was able to configure the router completely through one command prompt, which made it easily integrated into the System Exec VI.

0 Kudos
Message 5 of 6
(1,430 Views)

@alexm1 wrote:

Thanks everyone for the advice! I ended up using plink on windows, which you can specify a password, set it to non-interactive, and feed in a txt file with commands to run on the router. The full command I used was:

plink username@IP -batch -pw YourPassword -m “C:\Your file location.txt”

 

In plink:

-batch specifies to remove the interactive part of plink requiring you to press return after signing in

-pw allows you to enter your password in the command

-m allows you to specify the location of a text file that contains all of the commands that you want to run once you’ve entered ssh.

 

Hope this helps someone else in the future! I was able to configure the router completely through one command prompt, which made it easily integrated into the System Exec VI.


Sorry, I thought you wanted to create a library of commands, not just send a few specific ones.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 6
(1,424 Views)