# Net::SSH - how to respond to a prompt before first command?

**URL:** <https://www.ruby-forum.com/t/net-ssh-how-to-respond-to-a-prompt-before-first-command/142701>\
**Category:** Ruby\
**Created:** [July 10, 2008, 2:20pm UTC](https://www.ruby-forum.com/t/net-ssh-how-to-respond-to-a-prompt-before-first-command/142701 "2008-07-10T14:20:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![slawek\_zachcial](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/51bf81/32.png) [@slawek\_zachcial](https://www.ruby-forum.com/u/slawek_zachcial)\
**Post date:** [July 10, 2008, 2:20pm UTC](https://www.ruby-forum.com/t/net-ssh-how-to-respond-to-a-prompt-before-first-command/142701/1 "2008-07-10T14:20:26Z")

</div>

Hello,

I’m trying to connect, using SSH, to a server that immediately after  
login executes a script that requires input from user. The script is  
asking the user to select the target username that the shell should  
switch to. I’m using WinXP to run the script, the target server is  
running HP-UX and the user is switched using ‘pbrun’ command.

Here is the code I used to connect and then execute the “date” command:

Net::SSH.start(myhost, myuser, :password =\> mypassword, :keys =\> mykeys,  
:passphrase =\> mypassphrase, :verbose =\> :debug) do |ssh|  
puts ’ ######’, ’ #’, ’ # ’ + ssh.exec!(“date”), ’ #’, ’ ######’  
end

When I run this script connecting to another host which does not require  
the user input immediately after login everything works fine. That’s why  
I suspect that the user input part is causing the problem.

I attached the logs generated by the script for the “Working Scenario”  
and “Not Working Scenario”.

When I execute the script connecting to the server where it does not  
work, the script basically hangs.

I tried all kind of things with channels, I also looked through this  
forum and generally on the web. No luck. I admit that I’m a Ruby newbie  
so I may be missing something obvious here.

Any help would be greatly appreciated.

Thanks,  
/Slawek
