HP Procurve hangs after SSH logon just after "Press any key" message

Sep 17, 2012 at 3:44 PM

I'm building a PowerShell tool to do some tasks with HP Procurve Switches.

The problem seems that i can't handle correctly the interactive TTY and i was unable to send a carraige return or something after the "press any key" message.

I've instanced a SshNet.ShellStream into a variable (with the CreateShellStream method), so i've sucesfully used the method .Expect('Press any key to continue') to get the response of the SSH conection printing the whole thing into my local host.

But if i try with a .WriteLine() method includng any key or CarriageReturn codes, it doesn't seem to interactively pressa a key for the HP Procurve side... so, my SSH ShellStream hangs if i try to invoke the .ReadLine() method just after the "Press any key" message displayed by de HP Procurve switch.

Any ideas about how to bypass this problem?.

Thanks in advance...

 

 

Sep 17, 2012 at 4:37 PM
Edited Sep 17, 2012 at 4:53 PM

Just the Piece of PowerShell code that i did:

function execSshProcurve ([string]$command) {
	$IP_ProcurveSwitch = '172.xx.xx.xx';
	$ssh_user = [Environment]::UserName;
	New-SShSession -Computername $IP_ProcurveSwitch -Username $ssh_user;
	$ProcurveConsole = $SshSessions.$IP_ProcurveSwitch.CreateShellStream("procurve", 80, 24, 800, 600, 1024)
	$Reply = $ProcurveConsole.Expect('Press any key to continue');
	Write-Host $Reply;
	start-sleep -m 1000;
	Write-Host 'Print Carriage Return code in powershell or VT100 ESC sequences'		
	$ProcurveConsole.WriteLine('`r');
	$ProcurveConsole.WriteLine('^m');
	start-sleep -m 1000;
	$ProcurveConsole.WriteLine($command);
	Write-Host 'Can I still read? ' + $ProcurveConsole.CanRead; 
	# It says "true" for CanRead
	$Line = $ProcurveConsole.ReadLine();
	Write-Host $Line;
	Remove-SshSession -Computername $IP_ProcurveSwitch;
}

The thing hangs in the .ReadLine() method

Sep 17, 2012 at 10:50 PM

you try this?

http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library

you should be able to do new-sshsession and then invoke-sshcommand, first time just send a space to get past the "press any key"

 

try it in an interactive PS console first, to help account for delays in the SSH part..

Aug 15, 2013 at 5:43 AM
did you get this to work?