8

Ruby Net :: SSH method indefinite 'shell'

 3 years ago
source link: https://www.codesd.com/item/ruby-net-ssh-method-indefinite-shell.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Ruby Net :: SSH method indefinite 'shell'

advertisements

I'm trying to log into a remote machine using SSH in my Ruby code and then trying to cd into another directory once I SSHed in. Here is my Ruby code to do it

require 'net/ssh'
require 'rubygems'
require 'needle'

Net::SSH.start('host', 'shui', :password => "password") do |ssh|
   output = ssh.exec!("hostname")
   shell = ssh.shell.open
   shell.pwd
   shell.cd "/svn"
   puts shell.pwd
end

when I run my script, it gives me this error:

testssh.rb:8:in `block in <main>': undefined method `shell' ... (NoMethodError)

I'm pretty sure I've installed the gems that are needed to do this. Any suggestions on how to fix this? Thanks!


There is no shell method in Net:SSH v2, the yielded object is a Net::SSH::Connection::Session.

This net-ssh extension gives you the feature you are looking for: https://github.com/mitchellh/net-ssh-shell

Related Articles

Ruby NET :: SSH - Can not connect to remote server

I've been trying for days to connect my application to a remote server with the NET::SSH gem without success. The issue seems to originate from the fact I need to use a private key file to authenticate the login. require 'net/ssh' def SSH(host, user,

Net :: SSH :: Shell :: Process $ DONTEVERUSETHIS

When using Net::SSH to run commands on a remote connection, it adds the following script to the end of each and every command: DONTEVERUSETHIS=$?; echo #{manager.separator} $DONTEVERUSETHIS; echo \"exit $DONTEVERUSETHIS\"|sh the output produced

Using Ruby and net-ssh, how do I authenticate using the key_data parameter with Net :: SSH.start?

I've read the net-ssh documentation, and I am still perplexed. I can authenticate manually (using ssh -i ...), and also by placing the key in a file and using the :keys parameter. However, I dont want to use the :keys parameter, I want to use the :ke

get information from the remote system by using the sudo command using net :: ssh to ruby

I have a situation as i have to login to remote system and get the their hardware information. I logged in to their system i have used ssh for this i am using net-ssh gem. here is my code where i logged into and get the info Net::SSH.start('host','us

Sudo via net :: ssh to ruby

Here's how at the moment I send commands to a remote server: Net::SSH.start("1.2.3.4", keys: ["~/.ssh/id_rsa.pub"]) do |ssh| ssh.exec!(cmd_item) end How would I execute a command which requires root, that is "sudo apt-get install

The Net :: SSH sudo command crashes after entering the password

I've been trying to write a small library using Thor to help assist me in quick creating new projects and sites. I wrote this small method: def ssh(cmd) Net::SSH.start( server_ip, user, :port => port) do |session| session.exec cmd end end to just ass

Net-ssh timeout for execution?

In my application I want to terminate the exec! command of my SSH connection after a specified amount of time. I found the :timeout for the Net::SSH.start command but following the documentation this is only for the initial connection. Is there somet

How to properly transfer Net :: SSH port

I have been trying to get port forwarding to work correctly with Net::SSH. From what I understand I need to fork out the Net::SSH session if I want to be able to use it from the same Ruby program so that the event handling loop can actually process p

Net :: SSH :: AuthenticationFailed: Authentication Failed for User

Local Computer Username: Christopher Ubuntu Server Username: my_app_name I have followed the Digital Ocean documentation to set up an Ubuntu 16.04 server with Ruby on Rails and is my first time doing so, though when I get to cap production deploy:ini

Ruby Net-SFTP does not block on download

I'm using the ruby library Net-SFTP to upload a folder of a files to a remote server using the upload! command, and finding that when I regain control, the folder has not finished uploading. It wouldn't be all that important except for the fact that

Delete anything other than file + linked file on multiple servers (NET :: SSH :: MULTI)

I've got a couple of thousand images that are saved as logs that need to be deleted. To avoid the limit of rm and to do this across multiple servers, I used the following code Net::SSH::Multi.start(:on_error => :ignore) do |session| # define servers

Export the path using NET :: SSH: PERL

I am writing a shell script to automate some of the tedious tasks that we perform. I need to ssh to a server and change the PATH variable remotely, have that variable persist for the next commands to be executed. Code below; sub ab_tier{ my $ssh=Net:

Ruby net / smtp badly assigned email subject

I use Ruby net/smtp require 'net/smtp' I send mails using the following method: Net::SMTP.start(SMTP_SERVER) do |smtp| smtp.send_message(message,"[email protected]",reciepent) end I want to add a subject to the mails i send but couldn't fi

Ruby net / sftp read the file remotely and save to the database, get StatusException error (4, & ldquo; failure & rdquo;)

I'm trying to download xmls from a remote sftp site, read the contents of the file into REXML and save the data to the DB. so far the code is up to reading the file and f.gets line fails with the error: /usr/local/lib/ruby/gems/1.9.1/gems/net-sftp-2.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK