Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to assign CLI variables from CLI output
    primarykey
    data
    text
    <p>How do you arbitrarily extract output from CLI?</p> <p>In my specific example (but the answer should generically apply to the whole) I'm trying to write a general-purpose deploy/scale script for a NodeJS/MongoDB technology stack ontop of AWS EC2/EBS with standard Ubuntu server OS (12.04). For now, I'm manually creating and attaching the EBS drives through the AWS Dashboard Console, but everything else should happen automatically, without ever having to SSH in and do stupid CLI (though eventually I want to automate the create&amp;attach parts as well).</p> <p>So first, I need to get a list of all the blocks <code>lsblk -l</code> that are EBS drives to mount. Then I need to (on first time conditions) setup MDADM and LVM, however their commands assume that I know the names of the blocks, such as: </p> <pre><code>sudo mdadm --create --verbose /dev/md0 --level=10 --chunk=256 --raid-devices=4 /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4 </code></pre> <p>and so on. This is great and easy... IF I am a human reading through the CLI output from lsblk. But how does one parse/extract and iterate through it dynamically? Somehow I need to do this (pseudo code):</p> <pre><code>$EBS_ARRAY = lsblk -l -list_the_names_of_blocks_not_mounted sudo mdadm --create --verbose /dev/md0 --level=10 --chunk=256 --raid-devices=EBS_ARRAY.length EBS_ARRAY.join(' ') ...rest of my script here... </code></pre> <p>You can obviously see that I am a javascript guy clueless about how to work dynamically with CLI without JSON and non-interactively (scripted). So... How on earth do you arbitrarily extract information out of CLI output, in an automated way, into variables?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload