Difference between revisions of "Skel.rb"

From PeformIQ Upgrade
Jump to navigation Jump to search
(Created page with '=Skelton Ruby Script= <pre> </pre> category:Ruby Category:Examples')
 
Line 2: Line 2:


<pre>
<pre>
#!/usr/bin/env ruby
require 'getoptlong' 
 
# Call using "ruby tsftpc.rb -hftp.ibiblio.org -n21 -uanonymous -ps@s.com" 
# The parameters can be in any order 
unless ARGV.length == 4 
  puts "Usage: ruby tsftpc.rb -hftp_site_url -nport_no -uuser_name -ppassword" 
  exit 
end 
 
host_name = port_no = user_name = password = '' 
# specify the options we accept and initialize the option parser 
opts = GetoptLong.new( 
[ "--hostname", "-h", GetoptLong::REQUIRED_ARGUMENT ], 
[ "--port", "-n", GetoptLong::REQUIRED_ARGUMENT ], 
[ "--username", "-u", GetoptLong::REQUIRED_ARGUMENT ], 
[ "--pass", "-p", GetoptLong::REQUIRED_ARGUMENT ] 
# process the parsed options 
opts.each do |opt, arg| 
  case opt 
    when '--hostname' 
      host_name = arg 
    when '--port' 
      port_no = arg 
    when '--username' 
      user_name = arg 
    when '--pass' 
      password = arg 
  end 
end
</pre>
</pre>


[[category:Ruby]]
[[category:Ruby]]
[[Category:Examples]]
[[Category:Examples]]

Revision as of 09:13, 13 March 2012

Skelton Ruby Script

#!/usr/bin/env ruby

require 'getoptlong'  
  
# Call using "ruby tsftpc.rb -hftp.ibiblio.org -n21 -uanonymous -ps@s.com"   
# The parameters can be in any order   

unless ARGV.length == 4   
  puts "Usage: ruby tsftpc.rb -hftp_site_url -nport_no -uuser_name -ppassword"  
  exit   
end  
  
host_name = port_no = user_name = password = ''  

# specify the options we accept and initialize the option parser   

opts = GetoptLong.new(   
[ "--hostname", "-h", GetoptLong::REQUIRED_ARGUMENT ],   
[ "--port", "-n", GetoptLong::REQUIRED_ARGUMENT ],   
[ "--username", "-u", GetoptLong::REQUIRED_ARGUMENT ],   
[ "--pass", "-p", GetoptLong::REQUIRED_ARGUMENT ]   
)   

# process the parsed options   

opts.each do |opt, arg|   
  case opt   
    when '--hostname'  
      host_name = arg   
    when '--port'  
      port_no = arg   
    when '--username'  
      user_name = arg   
    when '--pass'  
      password = arg   
  end  
end