I scheduled this cronjob:
ruby twitter_bots/tweet_bots.rb
tweet_bots.rb:
#!/usr/bin/ruby
require 'rubygems'
require '/home/david/twitter_bots/twitterbot.rb'
mcnulty = TwitterBot.new('jamesmcnulty')
mcnulty.tweet
mcnulty.reply
mcnulty.close
twitterbot.rb:
require 'dbi'
require 'twitter'
class TwitterBot
...
The cron has these environmental variables:
SHELL=/bin/sh
PATH=/home/david/.rvm/gems/ruby-1.9.2-p290/bin:/home/david/.rvm/gems/ruby-1.9.2-p290#global/bin:/home/david/.rvm/rubies/ruby-1.9.2-p290/bin:/home/david/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
HOME=/home/david
LOGNAME=david
But it throws this error:
/home/david/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- deprecated (LoadError)
from /home/david/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/david/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/dbi.rb:48:in `<top (required)>'
from /home/david/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/david/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/david/twitter_bots/twitterbot.rb:1:in `<top (required)>'
from /home/david/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/david/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from twitter_bots/tweet_bots.rb:5:in `<main>'
I can see that the error comes from /home/david/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/dbi.rb:48 where it has require "deprecated"
But I have the deprecated gem v 2.0.1 installed. I also tried it with version 3.0.0.
When I run it manually, it works. What's wrong with the cron?
I am guessing you need the deprecated Gem.
try:
[sudo] gem install deprecated
Related
I ran into the error when I tried to run SQL through ruby script. Can someone help me figure out what could be the cause? I already looked for some similar posts but couldn't find the right solution yet.
/Users/User/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require': Could not load 'active_record/connection_adapters/redshift_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile. (LoadError)
from /Users/User/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/pg-0.17.1/lib/pg.rb:4:in `<top (required)>'
from /Users/User/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
from /Users/User/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activerecord4-redshift-adapter-0.2.1/lib/active_record/connection_adapters/redshift_adapter.rb:17:in `<top (required)>'
from /Users/User/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in `require'
from /Users/User/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in `rescue in require'
from /Users/User/.rbenv/versions/2.4.3/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:39:in `require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activerecord-4.2.10/lib/active_record/connection_adapters/connection_specification.rb:175:in `spec'
from /Users/User/.rvm/gems/ruby-2.4.3/gems/activerecord-4.2.10/lib/active_record/connection_handling.rb:50:in `establish_connection'
from /Users/User/Desktop/github/tracker/app/workers/appsflyer_importer_worker_aggregate.rb:100:in `fetch_data'
from /Users/User/Desktop/github/tracker/app/workers/appsflyer_importer_worker_aggregate.rb:120:in `perform'
from -:30:in `<main>'
Here is my settings:
Gemfile
ruby '2.4.3'
gem 'activerecord4-redshift-adapter', '~> 0.2'
gem 'pg'
Ruby version
ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin17]
Gem list
activerecord (4.2.10, 4.2.8)
activerecord4-redshift-adapter (0.2.1)
pg (1.0.0, 0.17.1)
Script
require 'active_record'
conn = {
adapter: 'redshift',
database: '#database',
host: '#host',
port: 5439,
username: '#username',
password: '#password'
}
ActiveRecord::Base.establish_connection(conn)
sql = 'select count(*) from table'
ActiveRecord::Base.connection.execute(sql)
You're using the pg gem version 1.0.0 and it is not compatible with the version of active_record and activerecord4-redshift-adapter that you're using:
The PGconn, PGresult, and PGError constants are deprecated, and will be removed as of version 1.0.
This can be seen in the history of the pg gem.
The activerecord4-redshift-adapter uses both the PGconn and PGError constants:
def connection_active?
#connection.status == PGconn::CONNECTION_OK
rescue PGError
false
end
Although I was unable to exactly duplicate the error message that you saw, by modifying the Gemfile to use an older version of the pg gem I was able to get farther along:
gem 'pg', '~> 0.21'
My exact steps were:
create the Gemfile
create a file test.rb containing your Ruby code
run bundle install
run bundle exec ruby test.rb
This produces the following error:
/Users/test/.rvm/gems/ruby-2.4.3/gems/activerecord4-redshift-adapter-0.2.1/lib/active_record/connection_adapters/redshift_adapter.rb:568:in `initialize': could not translate host name "#host" to address: nodename nor servname provided, or not known (PG::ConnectionBad)
This is almost certainly in the right direction for the problem you're having, and should put you on the path to accomplishing your goal.
I am using Ruby22-x64 just to let you know, but I successfully installed RedCloth-4.2.9 using gem install RedCloth within the command prompt. When I try to require 'rubygems' I get =>false which is normal because it's already loaded, but when I try require 'RedCloth this is the following error code I get:
irb(main):001:0> require 'RedCloth'
LoadError: cannot load such file -- 2.2/redcloth_scan
Couldn't load 2.2/redcloth_scan
The $LOAD_PATH was:
C:/Ruby22-x64/lib/ruby/gems/2.2.0/extensions/x64-mingw32/2.2.0/RedCloth- 4.2.9
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/RedCloth-4.2.9/lib
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/RedCloth- 4.2.9/lib/case_sensitive_require
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/RedCloth-4.2.9/ext
C:/Ruby22-x64/lib/ruby/site_ruby/2.2.0
C:/Ruby22-x64/lib/ruby/site_ruby/2.2.0/x64-msvcrt
C:/Ruby22-x64/lib/ruby/site_ruby
C:/Ruby22-x64/lib/ruby/vendor_ruby/2.2.0
C:/Ruby22-x64/lib/ruby/vendor_ruby/2.2.0/x64-msvcrt
C:/Ruby22-x64/lib/ruby/vendor_ruby
C:/Ruby22-x64/lib/ruby/2.2.0
C:/Ruby22-x64/lib/ruby/2.2.0/x64-mingw32
from C:/Ruby22-x64/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54
:in `require'
from C:/Ruby22-x64/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54
:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/RedCloth- 4.2.9/lib/RedCloth.
rb:13:in `<top (required)>'
from C:/Ruby22-x64/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:12
8:in `require'
from C:/Ruby22-x64/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:12
8:in `rescue in require'
from C:/Ruby22-x64/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39
:in `require'
from (irb):1
from C:/Ruby22-x64/bin/irb:11:in `<main>'
irb(main):002:0>
I don't know if it is the versions of RedCloth that may be doing this? Or some sort of path error? I really am looking for some help here though! Please!
I had to change the path by creating a 2.2 folder to include redcloth_scan.so and I got it to work!
Thanks for the link #Casper
I'm trying to install Chef solo on a VPS. I've installed Ruby and ran the install command for the Chef gems, however, when I check the version of Chef, it says that it can't load the file. I'm following along with the Railscast on the topic http://railscasts.com/episodes/339-chef-solo-basics?view=asciicast, except that I also installed rbenv and Ruby 2.0.0 as a preliminary step.
Can you identify what the cause of this error is?
root#Chef2:~# gem install chef ruby-shadow --no-ri --no-rdoc
Successfully installed chef-11.4.4
Building native extensions. This could take a while...
Successfully installed ruby-shadow-2.2.0
2 gems installed
root#Chef2:~# rbenv rehash
root#Chef2:~# chef-solo -v
/root/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- rubygems/format (LoadError)
from /root/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /root/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/chef-11.4.4/lib/chef/provider/package/rubygems.rb:34:in `<top (required)>'
from /root/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /root/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /root/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/chef-11.4.4/lib/chef/providers.rb:60:in `<top (required)>'
from /root/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /root/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /root/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/chef-11.4.4/lib/chef.rb:25:in `<top (required)>'
from /root/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /root/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /root/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/chef-11.4.4/lib/chef/application/solo.rb:19:in `<top (required)>'
from /root/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /root/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /root/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/chef-11.4.4/bin/chef-solo:23:in `<top (required)>'
from /root/.rbenv/versions/2.0.0-p195/bin/chef-solo:23:in `load'
from /root/.rbenv/versions/2.0.0-p195/bin/chef-solo:23:in `<main>'
Chef 11 is the latest version of chef and is now packaged with an embedded copy of ruby. See the following documentation:
http://wiki.opscode.com/display/chef/Installing+Chef+Client+and+Chef+Solo
What version of rubygem are you using?
Try using rubygems 1.8.25
I think the original poster may have been running into a ruby-2.0/rubygems-2.0 issue like CHEF-3933 on chef 11.4.4 Those have been fixed by now. Chef 11.10.0 supports ruby-2.1 + rubygems-2.2
Gem installs are highly discouraged if there's an omnibus installer. The railscast is now very out of date. Installation should be done with:
curl -L https://www.opscode.com/chef/install.sh | bash -s
My step is,
Execute RubyInstaller.exe file
install ruby
installed Path: c:\ruby193
install DevKit
gem install libxml-ruby --platform x86-mswin32-60
make test.rb file
require 'rubygems'
require 'xml'
ruby test.rb
print error msg
Error message:
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require':
126: The specified module could not be found - C:/Ruby193/lib/ruby/gems/1.9.1/gems/lib
xml-ruby-1.1.3-x86-mswin32-60/lib/libxml_ruby.so (LoadError)
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/libxml-ruby-1.1.3-x86-mswin32-6 0/lib/libxml.rb:9:in `<top (required)>'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/libxml-ruby-1.1.3-x86-mswin32-6 0/lib/xml.rb:11:in `<top (required)>'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from test.rb:2:in `<main>'
i want solution in this problem
plz. help me.
Had similar problem on Windows 7x64 with libxml-ruby 2.3.3 (Ruby 2, 1.9.3 and 1.9.2). As per this solution:
https://github.com/xml4r/libxml-ruby/issues/42#issuecomment-7040881
I managed my problem was also solved. Solution (thanks to the original author):
Locate 'libxml.rb' in libxml-ruby gem folder (something like 'C:\Ruby\Ruby192\lib\ruby\gems\1.9.1\gems\libxml-ruby-2.3.3-x86-mingw32\lib')
Add the following on top of the file:
ENV['PATH'] = ENV['PATH'] + ';' + File.expand_path(File.dirname(__FILE__) + '/libs')
Save and enjoy
I am trying to use FakeFS but keep getting an uninitialized constant error when I require 'fakefs':
C:/Ruby192/lib/ruby/gems/1.9.1/gems/fakefs-0.3.1/lib/fakefs/file.rb:26:in `<class:File>': uninitialized constant File::NOCTTY (NameError)
I was originally working in RubyMine, but to isolate the problem I wrote a simple hello world script and ran it from the command line, and still get the same error. Here is that script:
require 'rubygems'
gem 'fakefs'
require 'fakefs'
puts "Hello Cleveland!"
And here is the error and accompanying stacktrace:
>ruby foo.rb
C:/Ruby192/lib/ruby/gems/1.9.1/gems/fakefs-0.3.1/lib/fakefs/file.rb:26:in `<class:File>': uninitialized constant File::NOCTTY (NameError)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/fakefs-0.3.1/lib/fakefs/file.rb:4:in `<module:FakeFS>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/fakefs-0.3.1/lib/fakefs/file.rb:3:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/fakefs-0.3.1/lib/fakefs/safe.rb:9:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/fakefs-0.3.1/lib/fakefs.rb:1:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from foo.rb:3:in `<main>'
I installed the fakefs gem via RubyMine. I'm working on Windows with Ruby 1.9. Any ideas?
It's because Windows doesn't have NOCTTY and SYNC flags. You can add this method to the base.rb file:
def RealFile.const_missing const
const_set const, 42
end
Really, I don't know it cause any problems or not in the future but you'll be able to run your script at least. And I think you should write about this at github
There is a fork with some windows fixes (this guy commented all flags at all): https://github.com/vertiginous/fakefs