Solved

Need a hand on the split command in Chef / Ruby or a regex...

Posted on 2016-08-09
5
31 Views
Last Modified: 2016-08-15
I am using Chef / Ruby and I am using two environments 0001 and 0002..I have 2 log files that I want to lay down on two nodes on in each environment, so hope I make sense here.  I need to hopefully use split in Ruby to parse the 0001 / 0002 and determine which log file to lay down - one in 0001 and 0002 for the other, here is what I have in the configure.rb file:

environment_id = node[:chef_environment].split()

Log file names:

cwis_sdlc_0001.log

cwis_sdlc_0002.log

If I didn't give enough detail pls let me know.
0
Comment
Question by:Harper McDonald
  • 4
5 Comments
 
LVL 4

Author Comment

by:Harper McDonald
Comment Utility
UPDATE:

the node[:chef_environment].split()

should only return 0001 or 0002 and of course be put into environment_id
0
 
LVL 4

Author Comment

by:Harper McDonald
Comment Utility
Getting this now:

irb(main):006:0> log3.split("gryphon_cwis_sdlc_")
=> ["", "0002"]

Just need to remove the [ " and ,  --- any ideas?
0
 
LVL 34

Expert Comment

by:Dan Craciun
Comment Utility
Can you please provide the values of "node[:chef_environment]" and "$" ?

From the manual:
split(pattern=$;, [limit]) → anArray
Divides str into substrings based on a delimiter, returning an array of these substrings.

If pattern is omitted, the value of $; is used. If $; is nil (which is the default), str is split on whitespace as if ` ‘ were specified.
0
 
LVL 4

Accepted Solution

by:
Harper McDonald earned 0 total points
Comment Utility
nitro_environment_id = node[:chef_environment].split(//).last(4).join

I think I just found it out...
0
 
LVL 4

Author Closing Comment

by:Harper McDonald
Comment Utility
Found out experimenting
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article discusses four methods for overlaying images in a container on a web page
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now