IO.popen fails to pen persistent ssh connection

H

Hector Quiroz

What the?
The following code(see below) works fine in a few of my ruby scripts but
fails on others with the following message:

'/scripts/ruby/testssh.rb:4: undefined method `exitstatus' for
nil:NilClass (NoMethodError)'.

I know ssh is working and I can run ssh commands to #{hostname} using
#{username} credentials. I use this exact code in other scripts from the
same workstation, ssh'ing to the same remote host and it works fine.

I've copied the following lines and pasted them unto a new file and it
still fails with the above message.


#!/usr/bin/ruby -w
ssh = IO.popen("ssh #{username}@#{hostname} -T", "w+")
status = $?
break unless (status.exitstatus == 0)


Help...
Thank you

Hector
 
A

ara.t.howard

'/scripts/ruby/testssh.rb:4: undefined method `exitstatus' for
nil:NilClass (NoMethodError)'.

I know ssh is working and I can run ssh commands to #{hostname} using
#{username} credentials. I use this exact code in other scripts from
the
same workstation, ssh'ing to the same remote host and it works fine.

I've copied the following lines and pasted them unto a new file and it
still fails with the above message.


#!/usr/bin/ruby -w
ssh = IO.popen("ssh #{username}@#{hostname} -T", "w+")
status = $?
break unless (status.exitstatus == 0)

the process has not exited yet - $? is therefore nil.

a @ http://codeforpeople.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top