How do I get more than 100 records at a time from the Linode-CLI?
The Linode CLI offers easy command line access to just about anything you would do in the Linode Cloud Manager web interface. When asking for lists of items, the CLI provides 100 at a time, per 'page'.
If you are writing a script to obtain all of the items in a list, it can be tricky to know how many items (and by extension, how many pages) there are.
1 Reply
The Linode CLI offers multiple output formats: Human Readable (the default), Plain Text, and JSON.
It conveniently provides page information, when listing things using the Human Readable format, so this information is available.
For example if you want to know how many pages of records you will have to process:
linode-cli domains records-list 968719
┌──────────┬──────┬───────────┬────────────────────────────────┬─────────┬──────────┬────────┐
│ id │ type │ name │ target │ ttl_sec │ priority │ weight │
├──────────┼──────┼───────────┼────────────────────────────────┼─────────┼──────────┼────────┤
│ 19251843 │ A │ test01 │ 123.123.123.123 │ 0 │ 0 │ 0 │
│ 19251845 │ A │ test02 │ 123.123.123.123 │ 0 │ 0 │ 0 │
│ │ │ │ │ │ │ │
│ 19252035 │ A │ test169 │ 123.123.123.123 │ 0 │ 0 │ 0 │
│ 19251870 │ A │ test17 │ 123.123.123.123 │ 0 │ 0 │ 0 │
└──────────┴──────┴───────────┴────────────────────────────────┴─────────┴──────────┴────────┘
Page 1 of 3. Call with --page [PAGE] to load a different page.
We can extract this information with the following strategy:
- Get the last line of the output
- Ignore the beginning of the line through "Page 1 of "
- Capture all of the text up to the following string, ". Call", and ignore everything else to the end of the line.
Using the commands 'tail' and 'sed' the command pipeline looks like this:
bash$ linode-cli domains records-list 968719 | tail -n 1 | sed -e "s/^Page 1 of \(.*\)\. Call.*$/\1/"
3
You can assign the output of this command to a variable to use in your script:
bash$ cli_pages=`linode-cli domains records-list 968719 | tail -n 1 | sed -e "s/^Page 1 of \(.*\)\. Call.*$/\1/"`
bash$ echo $cli_pages
3
You can then loop through the pages to get your complete list:
bash$ for x in {1..$cli_pages}
for> do
for> linode-cli --text --no-headers --all domains records-list 968719 --page $x
for> done