Put as simply as possible, In Linux with bash/sed/awk and basic OS commands, I am attempting to create a list with multiple headings in a text file, with a bunch of strings underneath them (servernames). I then hope to be able to have a script go and run various tasks on each of the entries under a specific heading that I pass as an option/parameter at runtime.
Example of what this text file would look like: (these entries should be ordered UNDER the header in question in a single column, I just can't get it to display that way on this page.)
[main_server_list] Jupiter Saturn Thisguy Thatguy BuffalO randomspite coffeebinge [alternate_server_list] Jupiter Saturn [Tertiary_server_list] Thisguy Thatguy coffeebinge [Enough_already] BuffalO randomspite
So basically, if I wanted to copy a file to a directory to ALL of my machines, I would want to do something like:
# bash maincopyscript.sh [main_server_list]
And the "loop" would know that the list of servers to install this on would be every entry under the [main_server_list] header, but ignore everything else under any other header.
Similarly, I also want to be able to do:
# bash maincopyscript.sh [Tertiary_server_list]
And expect the same functionality, only this time, only run the "loop" on entries under the [Tertiary_server_list] header, and then be finished.
Lastly, I would like to be able to specify multiple headers if I wish as well, specified in any order. Such as:
# bash maincopyscript.sh [Enough_already] [alternate_server_list]
It should then run the operations specified in the script on only the entries under those 2 headers, and then be finished.
Hopefully you get the idea, basically a way to do this utilizing bash/sed/awk mainly. (or even another tool if necessary)
Yes yes, I understand that ansible/puppet/chef can also help me achieve these results, but I have specific reason for wanting to do this regardless. I tried to search for an hour or 2 for any pre-existing post on this, but couldn't find one, so finally decided to ask my question. Any help would be appreciated!
(Bonus, if anyone could also show me how to put entries under each header in alphabetical order while keeping the headers and groups themselves in the exact same formations that would be great too!)