Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. require 'optparse'
  2. require 'micro-optparse'
  3. # --command execue --query unix command --Servername abc123
  4. f =File.open("list_of_commands.txt", "r")
  5. f.each_line { |line|
  6. line= line.chomp
  7. #line = "--c execue --query unix --Servername abc123"
  8. #line = eval(""#{line}"")
  9. puts line
  10.  
  11. options = {}
  12. OptionParser.new do |opts|
  13.  
  14. opts.on("-c", "--command result,execue,chart,scpfile", String, "Single command to execute ") do |c|
  15. options[:comd] = c
  16. end
  17.  
  18. opts.on("-q", "--query remote command, unix command", String, "performs the command on local or remote machine") do |q|
  19. options[:query] = q
  20. end
  21.  
  22. opts.on("-s", "--servername CHSXEDWDC002 ", String, "server name to execute the command") do |v|
  23. options[:hname] = v
  24. end
  25.  
  26. opts.on_tail('-h', '--help', 'Show this message') do
  27. puts opts
  28. exit
  29. end
  30.  
  31. end.parse!(line)
  32. p options
  33. }
  34.  
  35. OptionParser.new do |opts|
  36. #...
  37. end.parse!(Shellwords.shellsplit(line))
  38.  
  39. require 'yaml'
  40.  
  41. data = {
  42. 'command' => %w[result execute chart scpfile],
  43. 'query' => ['remote command', 'unix command'],
  44. 'servername' => 'CHSXEDWHDC002',
  45. }
  46.  
  47. puts data.to_yaml
  48.  
  49. ---
  50. command:
  51. - result
  52. - execute
  53. - chart
  54. - scpfile
  55. query:
  56. - remote command
  57. - unix command
  58. servername: CHSXEDWHDC002
  59.  
  60. require 'yaml'
  61.  
  62. data = YAML.load_file('path/to/data.yaml')
  63.  
  64. require 'yaml'
  65.  
  66. data = {
  67. 'command' => %w[result execute chart scpfile],
  68. 'query' => ['remote command', 'unix command'],
  69. 'servername' => 'CHSXEDWHDC002',
  70. }
  71.  
  72. YAML.load(data.to_yaml)
  73.  
  74. {"command"=>["result", "execute", "chart", "scpfile"],
  75. "query"=>["remote command", "unix command"],
  76. "servername"=>"CHSXEDWHDC002"}
  77.  
  78. require 'optparse'
  79. require 'yaml'
  80.  
  81. # Note, YAML can deal with symbols as keys, but other languages might not like them.
  82. options = {
  83. :comd => %w[result execute chart scpfile],
  84. :query => ['remote command', 'unix command'],
  85. :hname => 'CHSXEDWHDC002',
  86. }
  87.  
  88. # we'll overwrite the options variable to pretend we loaded it from a file.
  89. options = YAML.load(options.to_yaml)
  90.  
  91. OptionParser.new do |opts|
  92.  
  93. opts.on("-c", "--Command result,execue,chart,scpfile", String, "Single command to execute ") do |c|
  94. options[:comd] = c
  95. end
  96.  
  97. opts.on("-q", "--query remote command, unix command", String, "performs the command on local or remote machine") do |q|
  98. options[:query] = q
  99. end
  100.  
  101. opts.on("-s", "--Servername CHSXEDWHDC002 ", String, "server name to execute the command") do |v|
  102. options[:hname] = v
  103. end
  104.  
  105. opts.on_tail('-h', '--help', 'Show this message') do
  106. puts opts
  107. exit
  108. end
  109.  
  110. end.parse!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement