У меня есть два кода ruby, один из них ssh.rb, а другой - generate_ip.rb, все они находятся в одном каталоге. Когда я импортирую ssh.rb в 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)
generate_ip.rb ↓
require './ssh.rb'
это моя структура каталогов ↓
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
это полный код:
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)
я пытаюсь require_relative
, это не работает -, -
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 (аналогично 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).
...
...
...
Несмотря ни на что, я очень благодарен всем тем, кто может дать мне совет.