Simple, simple stuff

Hello,
I just rebuilt my Mac, with Ruby. I’m getting these what I think are
very primitive errors when I try to run one of my scripts locally.

pb4072imac:~ peterbailey$ checkorca dy3242g1
/scripts/checkorca.rb: line 2: require: command not found
/scripts/checkorca.rb: line 4: require: command not found
/scripts/checkorca.rb: line 6: orcafile: command not found
host: couldn’t get address for ‘http://ps2000-graphics-prod.bna.com’:
not found
/scripts/checkorca.rb: line 10: clnt: command not found
/scripts/checkorca.rb: line 11: syntax error near unexpected token
nil,' /scripts/checkorca.rb: line 11:clnt.set_auth(nil, ‘production’,
‘prod’)’

What is it complaining about “require?” Yeh, I’ve got “require” there at
the top. But, I need it there.
And, why can’t it find the address of that URL?

Thanks,
Peter

“Jesús Gabriel y Galán” [email protected] wrote in post
#1130870:

On Tue, Dec 17, 2013 at 6:12 PM, Peter B. [email protected]
wrote:

/scripts/checkorca.rb: line 10: clnt: command not found
/scripts/checkorca.rb: line 11: syntax error near unexpected token
nil,' /scripts/checkorca.rb: line 11:clnt.set_auth(nil, ‘production’,
‘prod’)’

What is it complaining about “require?” Yeh, I’ve got “require” there at
the top. But, I need it there.
And, why can’t it find the address of that URL?

Hi,

I don’t work with a Mac, so take this with a grain of salt: it looks
like instead of running the script with the Ruby interpreter you are
running it as if it were a shell script, hence all the “command not
found” errors, cause the shell can’t find those commands. Do you have
an appropriate shebang line (not sure how that would look like in a
Mac):

something like:

#!/bin/env ruby

Otherwise you could try calling ruby directly:

$ ruby checkorca.rb dy3242g1

Jesus.

Thanks, Jesus. I checked my script and I do have the shebang there.
Thanks, anyway.

On Tue, Dec 17, 2013 at 6:12 PM, Peter B. [email protected]
wrote:

/scripts/checkorca.rb: line 10: clnt: command not found
/scripts/checkorca.rb: line 11: syntax error near unexpected token
nil,' /scripts/checkorca.rb: line 11:clnt.set_auth(nil, ‘production’,
‘prod’)’

What is it complaining about “require?” Yeh, I’ve got “require” there at
the top. But, I need it there.
And, why can’t it find the address of that URL?

Hi,

I don’t work with a Mac, so take this with a grain of salt: it looks
like instead of running the script with the Ruby interpreter you are
running it as if it were a shell script, hence all the “command not
found” errors, cause the shell can’t find those commands. Do you have
an appropriate shebang line (not sure how that would look like in a
Mac):

something like:

#!/bin/env ruby

Otherwise you could try calling ruby directly:

$ ruby checkorca.rb dy3242g1

Jesus.

On Tue, Dec 17, 2013 at 11:22 AM, Peter B. [email protected]
wrote:

What is it complaining about “require?” Yeh, I’ve got “require” there at
Mac):

Thanks, Jesus. I checked my script and I do have the shebang there.
Thanks, anyway.


Posted via http://www.ruby-forum.com/.

It might help if you pasted the script.

tamouse m. wrote in post #1130882:

On Tue, Dec 17, 2013 at 11:22 AM, Peter B. [email protected]
wrote:

What is it complaining about “require?” Yeh, I’ve got “require” there at
Mac):

Thanks, Jesus. I checked my script and I do have the shebang there.
Thanks, anyway.


Posted via http://www.ruby-forum.com/.

It might help if you pasted the script.

Uh, it’s pretty big. But, here it is. Thanks.

#/Users/peterbailey/.rbenv/shims/ruby
require ‘rubygems’
#noinspection RubyResolve
require ‘httpclient’

orcafile = ARGV[0]

host = ‘http://ps2000-graphics-prod.bna.com
#noinspection RubyResolve
clnt = HTTPClient.new
clnt.set_auth(nil, ‘production’, ‘prod’)

#Find PNG on Orca
format = ‘png’
url = URI.parse("#{host}/images/view/#{format}/#{orcafile}")
pngfile = orcafile + ‘.png’
response = clnt.head(url)
#noinspection RubyResolve
if HTTP::Status.successful?(response.status)
puts “#{pngfile} is on Orca.\n”
else
puts “#{pngfile} is NOT on Orca.\n”
end

#Find PDF on Orca
format = ‘pdf’
url = URI.parse("#{host}/images/view/#{format}/#{orcafile}")
pdffile = orcafile + ‘.pdf’
response = clnt.head(url)
#noinspection RubyResolve
if HTTP::Status.successful?(response.status)
puts “#{pdffile} is on Orca.\n”
else
puts “#{pdffile} is NOT on Orca.\n”
end

#Find TIFF on Orca
format = ‘tiff’
url = URI.parse("#{host}/images/view/#{format}/#{orcafile}")
tifffile = orcafile + ‘.tif’
response = clnt.head(url)
#noinspection RubyResolve
if HTTP::Status.successful?(response.status)
puts “#{tifffile} is on Orca.\n”
else
puts “#{tifffile} is NOT on Orca.\n”
end

#Find GIF on Orca
format = ‘gif’
url = URI.parse("#{host}/images/view/#{format}/#{orcafile}")
giffile = orcafile + ‘.gif’
response = clnt.head(url)
#noinspection RubyResolve
if HTTP::Status.successful?(response.status)
puts “#{giffile} is on Orca.\n”
else
puts “#{giffile} is NOT on Orca.\n”
end

#Find EPS on Orca
format = ‘eps’
url = URI.parse("#{host}/images/view/#{format}/#{orcafile}")
epsfile = orcafile + ‘.eps’
response = clnt.head(url)
#noinspection RubyResolve
if HTTP::Status.successful?(response.status)
puts “#{epsfile} is on Orca.\n”
else
puts “#{epsfile} is NOT on Orca.\n”
end

puts “\n”

#PS2000 Files
orcafile = File.basename(orcafile, ‘.*’)

if orcafile.match(/^ehs-/)
exit
end

if File.exist?("/volumes/graphics/artrefpdf_color/master/#{orcafile}")
filetime =
File.stat("/volumes/graphics/artrefpdf_color/master/#{orcafile}").mtime
filedirectory = ‘/volumes/graphics/artrefpdf_color/master/’
filetime = filetime.to_s.gsub(/ -0[0-9]00/, ‘’)
puts “#{orcafile} is in the Color PS2k image library at:
DIRECTORY #{filedirectory}\n DATED #{filetime}\n”
end

if File.exist?("/volumes/graphics/images_9/master/#{orcafile}")
filetime =
File.stat("/volumes/graphics/images_9/master/#{orcafile}").mtime
filedirectory = ‘/volumes/graphics/images_9/master/’
filetime = filetime.to_s.gsub(/ -0[0-9]00/, ‘’)
#noinspection RubyResolve,RubyResolve,RubyResolve
puts “#{orcafile} is in the regular PS2K image library at:
DIRECTORY #{filedirectory}\n DATED #{filetime}.”
elsif File.exist?("/volumes/graphics/images_8/master/#{orcafile}")
filetime =
File.stat("/volumes/graphics/images_8/master/#{orcafile}").mtime
filedirectory = ‘/volumes/graphics/images_8/master/’
filetime = filetime.to_s.gsub(/ -0[0-9]00/, ‘’)
puts “#{orcafile} is in the regular PS2K image library at:
DIRECTORY #{filedirectory}\n DATED #{filetime}\n”
elsif File.exist?("/volumes/graphics/images_7/master/#{orcafile}")
filetime =
File.stat("/volumes/graphics/images_7/master/#{orcafile}").mtime
filedirectory = ‘/volumes/graphics/images_7/master/’
filetime = filetime.to_s.gsub(/ -0[0-9]00/, ‘’)
puts “#{orcafile} is in the regular PS2K image library at:
DIRECTORY #{filedirectory}\n DATED #{filetime}\n”
elsif File.exist?("/volumes/graphics/images_6/master/#{orcafile}")
filetime =
File.stat("/volumes/graphics/images_6/master/#{orcafile}").mtime
filedirectory = ‘/volumes/graphics/images_6/master/’
filetime = filetime.to_s.gsub(/ -0[0-9]00/, ‘’)
puts “#{orcafile} is in the regular PS2K image library at:
DIRECTORY #{filedirectory}\n DATED #{filetime}\n”
elsif File.exist?("/volumes/graphics/images_5/master/#{orcafile}")
filetime =
File.stat("/volumes/graphics/images_5/master/#{orcafile}").mtime
filedirectory = ‘/volumes/graphics/images_5/master/’
filetime = filetime.to_s.gsub(/ -0[0-9]00/, ‘’)
puts “#{orcafile} is in the regular PS2K image library at:
DIRECTORY #{filedirectory}\n DATED #{filetime}\n”
elsif File.exist?("/volumes/graphics/images_4/master/#{orcafile}")
filetime =
File.stat("/volumes/graphics/images_4/master/#{orcafile}").mtime
filedirectory = ‘/volumes/graphics/images_4/master/’
filetime = filetime.to_s.gsub(/ -0[0-9]00/, ‘’)
puts “#{orcafile} is in the regular PS2K image library at:
DIRECTORY #{filedirectory}\n DATED #{filetime}\n”
elsif File.exist?("/volumes/graphics/images_3/master/#{orcafile}")
filetime =
File.stat("/volumes/graphics/images_3/master/#{orcafile}").mtime
filedirectory = ‘/volumes/graphics/images_3/master/’
filetime = filetime.to_s.gsub(/ -0[0-9]00/, ‘’)
puts “#{orcafile} is in the regular PS2K image library at:
DIRECTORY #{filedirectory}\n DATED #{filetime}\n”
elsif File.exist?("/volumes/graphics/images_2/master/#{orcafile}")
filetime =
File.stat("/volumes/graphics/images_2/master/#{orcafile}").mtime
filedirectory = ‘/volumes/graphics/images_2/master/’
filetime = filetime.to_s.gsub(/ -0[0-9]00/, ‘’)
puts “#{orcafile} is in the regular PS2K image library at:
DIRECTORY #{filedirectory}\n DATED #{filetime}\n”
elsif File.exist?("/volumes/graphics/images_1/master/#{orcafile}")
filetime =
File.stat("/volumes/graphics/images_1/master/#{orcafile}").mtime
filedirectory = ‘/volumes/graphics/images_1/master/’
filetime = filetime.to_s.gsub(/ -0[0-9]00/, ‘’)
puts “#{orcafile} is in the regular PS2K image library at:
DIRECTORY #{filedirectory}\n DATED #{filetime}\n”
else
puts “The file is not in the ps2000 image library. It’s probably for a
web-only service.”
end

Do you need the ‘bang’ - ! - in your shebang?

#!/ vs. #/

(I use Windows.)

Jacob V. wrote in post #1130886:

Do you need the ‘bang’ - ! - in your shebang?

#!/ vs. #/

(I use Windows.)

I tried it with the screamer (!), but, I still get the same results.

If I run the script like this in my Mac shell, I’m alright.

ruby checkorca.rb dy3242g1

Normally, I run it like this:

checkorca dy3242g1

because, I have a simple script in my scripts directory called
“checkorca” that simply calls out the Ruby script.

If I run this, it doesn’t run either.

checkorca.rb dy3242g1

It’s like there’s some disconnect with Ruby itself, or, at least, the
Ruby version I’m running. I used rbenv to install my Ruby.

Are you pointing to the ruby directory or the executable, you need to
point to the ruby executable?
Should it maybe be:
#!/Users/peterbailey/.rbenv/shims/ruby/bin/ruby

From: tamouse pontiki [email protected]
To: ruby-talk ML [email protected]
Date: 12/18/2013 01:06 AM
Subject: Re: simple, simple stuff
Sent by: “ruby-talk” [email protected]

On Tue, Dec 17, 2013 at 12:58 PM, Peter B. [email protected]
wrote:
tamouse m. wrote in post #1130882:

On Tue, Dec 17, 2013 at 11:22 AM, Peter B. [email protected]
wrote:

What is it complaining about “require?” Yeh, I’ve got “require”
there at

It might help if you pasted the script.

Uh, it’s pretty big. But, here it is. Thanks.

Thanks – it’s not that long, but I guess I could have asked for the
head of the file instead… :))

#/Users/peterbailey/.rbenv/shims/ruby

It should be:

#!/Users/peterbailey/.rbenv/shims/ruby

if you actually do have a shim for ruby at that exact path. Type that at
the Terminal prompt to see.

This is what I use to start scripts:

#!/usr/bin/env ruby

and it picks up which ruby to run based upon the user’s environment,
which defaults to the system ruby.

On Dec 18, 2013, at 1:05 AM, tamouse pontiki [email protected]
wrote:

Uh, it’s pretty big. But, here it is. Thanks.
if you actually do have a shim for ruby at that exact path. Type that at the
Terminal prompt to see.
One way to determine which ruby a particular shell will pick up is to
use the which command, for example:

ratdog:~ mike$ which ruby
/Users/mike/.rbenv/shims/ruby

Is that the same as the interpreter specified in the #! line?

To see if the interpreter in your #! line exists, you can check by using
ls, for example on my system I would do:

ratdog:~ mike$ ls -l /Users/mike/.rbenv/shims/ruby
-rwxr-xr-x 7 mike 501 408 28 Oct 13:18 /Users/mike/.rbenv/shims/ruby

If it does exist then I would check that the script is executable, and
that there are no invisible characters at the end of the #! line
(usually this happens when a file comes from windows to a unix-like
environment and what looks like ruby at the end of the line is really
ruby\r)

One way to “repair” this might be to use

which ruby

then delete the top line of the file, enter #!, and then copy and paste
the output of which ruby into the file.

In general I prefer #!/usr/bin/env ruby to hard coding a path because it
lets me switch between rbenv and rvm and not have to update all my
scripts having the .rbenv/shims in there explicitly couples your script
to the detail of how you currently install ruby.

Hope this helps,

Mike

This is what I use to start scripts:

#!/usr/bin/env ruby

and it picks up which ruby to run based upon the user’s environment, which
defaults to the system ruby.

Mike S. [email protected]
http://www.stok.ca/~mike/

The “`Stok’ disclaimers” apply.

unknown wrote in post #1130962:

Are you pointing to the ruby directory or the executable, you need to
point to the ruby executable?
Should it maybe be:
#!/Users/peterbailey/.rbenv/shims/ruby/bin/ruby

From: tamouse pontiki [email protected]
To: ruby-talk ML [email protected]
Date: 12/18/2013 01:06 AM
Subject: Re: simple, simple stuff
Sent by: “ruby-talk” [email protected]

On Tue, Dec 17, 2013 at 12:58 PM, Peter B. [email protected]
wrote:
tamouse m. wrote in post #1130882:

On Tue, Dec 17, 2013 at 11:22 AM, Peter B. [email protected]
wrote:

What is it complaining about “require?” Yeh, I’ve got “require”
there at

It might help if you pasted the script.

Uh, it’s pretty big. But, here it is. Thanks.

Thanks – it’s not that long, but I guess I could have asked for the
head of the file instead… :))

#/Users/peterbailey/.rbenv/shims/ruby

It should be:

#!/Users/peterbailey/.rbenv/shims/ruby

if you actually do have a shim for ruby at that exact path. Type that at
the Terminal prompt to see.

This is what I use to start scripts:

#!/usr/bin/env ruby

and it picks up which ruby to run based upon the user’s environment,
which defaults to the system ruby.

My shebank looks just like you suggest:
#!/Users/peterbailey/.rbenv/shims/ruby

If I were to use "#!/usr/bin/env ruby, would that still let me use the
latest Ruby that’s in /users/peterbailey/.rbenv/shims/ruby ??

If so, then, yeh, I’ll do that.

Thanks!

On Thu, Dec 19, 2013 at 8:41 AM, Peter B. [email protected]
wrote:

If what you have for your shebang matches exactly what you get when you
type which ruby at the command line, that should work. If you want to
try
out the other, you can also type that exactly at the command line.

This is mine:

$ which ruby
/opt/rubies/ruby-2.0.0-p247/bin/ruby

$ /opt/rubies/ruby-2.0.0-p247/bin/ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.5.0]

$ /usr/bin/env ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.5.0]
I happen to be using chruby, but rbenv and rvm will work the same if it
is
set up correctly, as will the system ruby. Chruby sets and exports the
following into the shell environment (which is what /usr/bin/env picks
up
for the shebang command):

GEM_HOME=/Users/tamara/.gem/ruby/2.0.0
GEM_PATH=/Users/tamara/.gem/ruby/2.0.0:/opt/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0
GEM_ROOT=/opt/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0
RUBYOPT=
RUBY_ENGINE=ruby
RUBY_ROOT=/opt/rubies/ruby-2.0.0-p247
RUBY_VERSION=2.0.0
You should be able to find the same env vars with settings appropriate
to
your setup.

On Tue, Dec 17, 2013 at 12:58 PM, Peter B. [email protected]
wrote:

Thanks, anyway.


Posted via http://www.ruby-forum.com/.

It might help if you pasted the script.

Uh, it’s pretty big. But, here it is. Thanks.

Thanks – it’s not that long, but I guess I could have asked for the
head
of the file instead… :))

#/Users/peterbailey/.rbenv/shims/ruby

It should be:

#!/Users/peterbailey/.rbenv/shims/ruby

if you actually do have a shim for ruby at that exact path. Type that at
the Terminal prompt to see.

This is what I use to start scripts:

#!/usr/bin/env ruby

and it picks up which ruby to run based upon the user’s environment,
which
defaults to the system ruby.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs