I have two ruby code, one is ssh.rb and the other is generate_ip.rb, they are all in the same directory. When I import ssh.rb in generate_ip.rb, I always getting the following error:
Traceback (most recent call last):
5: from generate_ip.rb:1:in `<main>'
4: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
3: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
2: from /root/ssh.rb:8:in `<top (required)>'
1: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- net/ssh/config (LoadError)
generate_ip.rb↓
require './ssh.rb'
this is my directory structure↓
root@BabyZe:~# ls -l
total 56
drwxr-xr-x 3 root root 4096 Apr 1 20:32 Desktop
drwxr-xr-x 2 root root 4096 Sep 27 2018 Documents
drwxr-xr-x 2 root root 4096 Sep 27 2018 Downloads
-rw-r--r-- 1 root root 32 May 3 07:36 generate_ip.rb
drwxr-xr-x 2 root root 4096 Sep 27 2018 Music
drwxr-xr-x 3 root root 4096 May 3 06:04 Notebooks
drwxr-xr-x 2 root root 4096 Sep 27 2018 Pictures
drwxr-xr-x 2 root root 4096 Sep 27 2018 Public
-rw-r--r-- 1 root root 15595 May 3 06:45 ssh.rb
drwxr-xr-x 2 root root 4096 Sep 27 2018 Templates
drwxr-xr-x 2 root root 4096 Sep 27 2018 Videos
it is a complete code:
root@BabyZe:~# ls -l
total 56
drwxr-xr-x 3 root root 4096 Apr 1 20:32 Desktop
drwxr-xr-x 2 root root 4096 Sep 27 2018 Documents
drwxr-xr-x 2 root root 4096 Sep 27 2018 Downloads
-rw-r--r-- 1 root root 19 May 3 07:48 generate_ip.rb
drwxr-xr-x 2 root root 4096 Sep 27 2018 Music
drwxr-xr-x 3 root root 4096 May 3 06:04 Notebooks
drwxr-xr-x 2 root root 4096 Sep 27 2018 Pictures
drwxr-xr-x 2 root root 4096 Sep 27 2018 Public
-rw-r--r-- 1 root root 15595 May 3 06:45 ssh.rb
drwxr-xr-x 2 root root 4096 Sep 27 2018 Templates
drwxr-xr-x 2 root root 4096 Sep 27 2018 Videos
root@BabyZe:~# cat generate_ip.rb
require './ssh.rb'
root@BabyZe:~# ruby generate_ip.rb
Traceback (most recent call last):
5: from generate_ip.rb:1:in `<main>'
4: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
3: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
2: from /root/ssh.rb:8:in `<top (required)>'
1: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- net/ssh/config (LoadError)
i try require_relative
, it doesn't work -,-
root@BabyZe:~# cat generate_ip.rb
require_relative 'ssh.rb'
root@BabyZe:~# ruby generate_ip.rb
Traceback (most recent call last):
4: from generate_ip.rb:1:in `<main>'
3: from generate_ip.rb:1:in `require_relative'
2: from /root/ssh.rb:8:in `<top (required)>'
1: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- net/ssh/config (LoadError)
ssh.rb(same as Net:SSH)↓
# Make sure HOME is set, regardless of OS, so that File.expand_path works
# as expected with tilde characters.
ENV['HOME'] ||= ENV['HOMEPATH'] ? "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}" : Dir.pwd
require 'logger'
require 'etc'
require 'net/ssh/config'
require 'net/ssh/errors'
require 'net/ssh/loggable'
require 'net/ssh/transport/session'
require 'net/ssh/authentication/session'
require 'net/ssh/connection/session'
require 'net/ssh/prompt'
module Net
# Net::SSH is a library for interacting, programmatically, with remote
# processes via the SSH2 protocol. Sessions are always initiated via
# Net::SSH.start. From there, a program interacts with the new SSH session
# via the convenience methods on Net::SSH::Connection::Session, by opening
# and interacting with new channels (Net::SSH::Connection:Session#open_channel
# and Net::SSH::Connection::Channel), or by forwarding local and/or
# remote ports through the connection (Net::SSH::Service::Forward).
...
...
...
No matter what, I am very grateful to all those who can give me advice.