LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Plink/PuTTY works 30% of the time using System Exec.vi

Solved!
Go to solution

I need to use SSH to login to a network switch to get the arp table. So I grabbed the Plink example found here.

 

Problem 1:

It works sometimes from within LabView. If you grab the Command Executed string and place it in the command window it always works. For some reason when run from LabView my host disconnects. It doesn't disconnect from the command line but does from the LabView system exec.vi.

 

Problem 2:

I need to capture the session text since it contains the data I need. I read in the documentation for PuTTY that there is a logging setting to save the session to a log file. You just have to have a saved session setting and can use the -load argument with Plink to use that sessions settings. If I use the session in Putty it works. When I use it from Plink it doesn't. I have resorted to redirection to get the session data.

 

I have modified the PuTTY.vi on the NI website to suite my purpose and it redirects properly but about 70% of the time the session terminates before its complete. Again works fine from a dos command window.

 

Any suggestions?

 

Norm

0 Kudos
Message 1 of 25
(13,482 Views)

Additional Info LabView 2013 System Exec.vi standard error

Standard error on failure:

Looking up host "blah.blah.blah.com"
Connecting to xx.xx.xx.xx port 22
Server version: SSH-2.0-Cisco-1.25
We believe remote version has SSH-1 ignore bug
We believe remote version needs a plain SSH-1 password
We believe remote version can't handle SSH-1 RSA authentication
Using SSH protocol version 2
We claim version: SSH-2.0-PuTTY_Release_0.63
Using Diffie-Hellman with standard group "group1"
Doing Diffie-Hellman key exchange with hash SHA-1
Host key fingerprint is:
ssh-rsa 4096 0c:67:c7:ff:f4:85:e7:f5:f6:a9:30:07:ef:83:e4:d9
Initialised AES-256 SDCTR client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
Using username "my_name".
Sent password
Access granted
Opening session as main channel
Opened main channel
Started a shell/command
Unable to read from standard input: The handle is invalid.

Standard error on sucess

Looking up host "blah.blah.blah.com"
Connecting to xx.xx.xx.xx port 22
Server version: SSH-2.0-Cisco-1.25
We believe remote version has SSH-1 ignore bug
We believe remote version needs a plain SSH-1 password
We believe remote version can't handle SSH-1 RSA authentication
Using SSH protocol version 2
We claim version: SSH-2.0-PuTTY_Release_0.63
Using Diffie-Hellman with standard group "group1"
Doing Diffie-Hellman key exchange with hash SHA-1
Host key fingerprint is:
ssh-rsa 4096 0c:67:c7:ff:f4:85:e7:f5:f6:a9:30:07:ef:83:e4:d9
Initialised AES-256 SDCTR client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
Using username "my_name".
Sent password
Access granted
Opening session as main channel
Opened main channel
Started a shell/command
Server sent command exit status 0
Disconnected: All channels closed

Success is less than 30%

 

Norm

0 Kudos
Message 2 of 25
(13,461 Views)

If you run out of ideas, you could always try a native SSH implementation through a 3rd party toolkit: http://sine.ni.com/nips/cds/view/p/lang/en/nid/210882

 

It's a paid toolkit but you might have more success with it.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 3 of 25
(13,424 Views)

I think this SSH toolkit is the reason NI has failed to develop a native solution. They don't want to pull the rug out from under one of their developers. But $1552 when LV is 3K? Really? At $500 I'd pull the trigger.

0 Kudos
Message 4 of 25
(13,413 Views)

Now that I've built an application with this method it never works. It seems that in the IDE it was slow to terminate and somtimes competed. Now that it is built it terminates much faster and never gets through. I even built this into a batch file so instead of calling putty from the system exec.vi i call a batch file from system exec.vi. The batch file calles putty. Running the batch file itself completes just fine every time but calling the batch from system exec.vi is hit and miss in the IDE and never completes from a built application.

0 Kudos
Message 5 of 25
(13,388 Views)

Early terminated session log

Type help or '?' for a list of available commands.

051-TCIFM-CF01/CUSTOMER> en
Password: ****

 Please note that the Password is inside the session. That Putty has already from the command line entered the password and made a connection. The connection is abruptly terminated. Where it terminates is complety variable from a few characters to all of the arp table but before the exit command. see below.

 

Completed session log

Type help or '?' for a list of available commands.

051-TCIFM-CF01/CUSTOMER> en
Password: ***********

051-TCIFM-CF01/CUSTOMER# sh arp
	
	ENG-TCIFM_CUSTOMER 192.168.0.174 0020.4af1.af29 27
	ENG-TCIFM_CUSTOMER 192.168.0.145 0020.4af1.acc9 27
	ENG-TCIFM_CUSTOMER 192.168.0.136 0020.4af6.2a03 46
	ENG-TCIFM_CUSTOMER 192.168.0.137 0020.3805.5801 49
	ENG-TCIFM_CUSTOMER 192.168.0.152 0020.4af1.ad47 59
	ENG-TCIFM_CUSTOMER 192.168.0.139 0020.3805.5813 95
	ENG-TCIFM_CUSTOMER 192.168.0.138 0020.4af1.ac93 110
	ENG-TCIFM_CUSTOMER 192.168.0.166 0020.4af6.29f9 115
	ENG-TCIFM_CUSTOMER 192.168.0.147 0020.3805.498f 124
	ENG-TCIFM_CUSTOMER 192.168.0.133 0020.3805.57fb 137
	ENG-TCIFM_CUSTOMER 192.168.0.148 0020.4af6.29be 144
	ENG-TCIFM_CUSTOMER 192.168.0.132 0020.4af6.2a28 168
	ENG-TCIFM_CUSTOMER 192.168.0.169 0020.4af6.2abd 171
	ENG-TCIFM_CUSTOMER 192.168.0.170 0020.3805.57ed 259
	ENG-TCIFM_CUSTOMER 192.168.0.153 0020.3805.5807 264
	ENG-TCIFM_CUSTOMER 192.168.0.149 0020.3805.57eb 408
	ENG-TCIFM_CUSTOMER 192.168.0.167 0020.3805.57e9 654
	ENG-TCIFM_CUSTOMER 192.168.0.178 0020.3805.3b4f 887
	ENG-TCIFM_CUSTOMER 192.168.0.177 0020.3805.493d 1710
	ENG-TCIFM_CUSTOMER 192.168.0.134 0020.4af6.2a34 2797
	ENG-TCIFM_CUSTOMER 192.168.0.135 0020.3805.57f5 2842

051-TCIFM-CF01/CUSTOMER#    

051-TCIFM-CF01/CUSTOMER# exit

Logoff

 On this one note that the script ran to completion and processed the last command "exit".

0 Kudos
Message 6 of 25
(13,347 Views)

I've been frustrated by the lack of SSH support myself. I started working on something, but later found a different way to do what I needed.

 

I'll share this; maybe someone can package and test it.

 

I downloaded and experimented with something called Renci SSH.NET

 

Extract this ZIP inside of your instr.lib folder.

 

The two most useful VIs woudl be Renci.Ssh.NET Command.vi and Renci.Ssh.NET SCP File.vi

 

(LabVIEW 2011)

 

 


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

Message 7 of 25
(13,340 Views)
Solution
Accepted by Viper

NI Support found the solution for me.

 

Hello Norm,

I have been looking into how the System Exec.vi processes command line applications.  I have been using the TIMEOUT 3 command.  I have noticed that when the “wait until completion?” input is set to default or true then the DOS command line window opens then immediately closes.  When this occurs, the LabVIEW program continues, without delaying 3 seconds.  When I have the value set to false, the DOS command line window opens and remains open until the 3 second delay elapses.  In this case, the LabVIEW program continues immediately, but the CMD windows is open and indicates that the delay is being processed and not being cut short.

I think that the System Exec.vi is aborting execution before the command has had time to process. Can you please try to set “wait until completion” to false, and insert a wait before you read the data from the log file?

Please let me know if you have any questions, by replying to this email without modifying the subject or calling 866-275-6964 and enter your service request number 2189211.

Regards,



Thomas Capuano
Applications Engineer
National Instruments

 Thanks Thomas

Norm

Message 8 of 25
(13,265 Views)

I also have this problem.. Can I ask a copy of a working code? Thanks..

0 Kudos
Message 9 of 25
(12,156 Views)

Have you tried implementing the solution using the System Exec.vi? Also, this is an old thread and you might have better luck starting fresh and describe what you're using (software, versions, ect..), what your goal is, what your problem is, and what you steps you've taken.

0 Kudos
Message 10 of 25
(12,109 Views)