Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'optparse'
- require 'micro-optparse'
- # --command execue --query unix command --Servername abc123
- f =File.open("list_of_commands.txt", "r")
- f.each_line { |line|
- line= line.chomp
- #line = "--c execue --query unix --Servername abc123"
- #line = eval(""#{line}"")
- puts line
- options = {}
- OptionParser.new do |opts|
- opts.on("-c", "--command result,execue,chart,scpfile", String, "Single command to execute ") do |c|
- options[:comd] = c
- end
- opts.on("-q", "--query remote command, unix command", String, "performs the command on local or remote machine") do |q|
- options[:query] = q
- end
- opts.on("-s", "--servername CHSXEDWDC002 ", String, "server name to execute the command") do |v|
- options[:hname] = v
- end
- opts.on_tail('-h', '--help', 'Show this message') do
- puts opts
- exit
- end
- end.parse!(line)
- p options
- }
- OptionParser.new do |opts|
- #...
- end.parse!(Shellwords.shellsplit(line))
- require 'yaml'
- data = {
- 'command' => %w[result execute chart scpfile],
- 'query' => ['remote command', 'unix command'],
- 'servername' => 'CHSXEDWHDC002',
- }
- puts data.to_yaml
- ---
- command:
- - result
- - execute
- - chart
- - scpfile
- query:
- - remote command
- - unix command
- servername: CHSXEDWHDC002
- require 'yaml'
- data = YAML.load_file('path/to/data.yaml')
- require 'yaml'
- data = {
- 'command' => %w[result execute chart scpfile],
- 'query' => ['remote command', 'unix command'],
- 'servername' => 'CHSXEDWHDC002',
- }
- YAML.load(data.to_yaml)
- {"command"=>["result", "execute", "chart", "scpfile"],
- "query"=>["remote command", "unix command"],
- "servername"=>"CHSXEDWHDC002"}
- require 'optparse'
- require 'yaml'
- # Note, YAML can deal with symbols as keys, but other languages might not like them.
- options = {
- :comd => %w[result execute chart scpfile],
- :query => ['remote command', 'unix command'],
- :hname => 'CHSXEDWHDC002',
- }
- # we'll overwrite the options variable to pretend we loaded it from a file.
- options = YAML.load(options.to_yaml)
- OptionParser.new do |opts|
- opts.on("-c", "--Command result,execue,chart,scpfile", String, "Single command to execute ") do |c|
- options[:comd] = c
- end
- opts.on("-q", "--query remote command, unix command", String, "performs the command on local or remote machine") do |q|
- options[:query] = q
- end
- opts.on("-s", "--Servername CHSXEDWHDC002 ", String, "server name to execute the command") do |v|
- options[:hname] = v
- end
- opts.on_tail('-h', '--help', 'Show this message') do
- puts opts
- exit
- end
- end.parse!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement