30 May 2019

Using traditional Unix tools with the Aiven CLI

Got bash, grep, cat and wc and want the the simplest commands to select, run and administer your Aiven services? Learn how.

john-hammink

John Hammink

|

RSS Feed

Developer Advocate at Aiven

Using traditional Unix tools with the Aiven CLI illustration

Things have moved on since 2019, and we've continued improving the Aiven command line tool. There's a new blog post at Get things done with the Aiven CLI which explains how to get started, and how to manage a PostgreSQL® service from start to finish. It also gives examples of using the --json switch and the jq tool to extract data in a more powerful way than with grep and friends.

You can do most of your Aiven service administration straight from your Aiven Console. However, for those times when you need to run a quick shell command on our CLI (command line interface) to check service status, power on or off services, filter through available plans or clouds, upgrade some of your services or watch for patterns in event logs, this guide is for you.

You can also use these commands for scripting and automation, as a basis for constructing your own commands or aliases, or even to dig deeper into the CLI for more possibilities. In this article, we’ll focus more on grepping through the sometimes rather lengthy and / or verbose avn outputs to find specific information more easily — although there are some admin and service deployment commands included.

While intended for use with our CLI, we also hope you’ll find this as a useful guide to get familiar with — or to revisit -- some basic bash scripting.

Feel free to copy / paste, but remember to adjust to the variables you need, for example your --cloud, and/or your --project setting depending on what you’re trying to do. Other variables may include such items as your login name as well as your chosen project and service instance names. Also, while we've specified writing to files or stdout; or clearing screens for aesthetic purposes, feel free to customize the commands you need.

Our list of commands here isn’t exhaustive but is complementary to the one on the Aiven client’s github profile, with some overlapping on the basic stuff. Be sure to check out both!

Finally, we’ll share the lot on github and include a few keyboard-friendly aliases for useful commands that you can use as a basis for some of your own Aiven service deployment and DevOps infrastructure.

You’ll need at least Python 2.7 or 3.4 or newer versions, with pip installed.

$ python -m pip install aiven-client

See the Aiven Client documentation on Github for instructions for other platforms.

NOTE: you’ll be prompted for your password.

avn user login <user@aiven.io>

avn user -h

avn user info

avn logout

avn service types

avn cloud list

avn cloud list | grep United

avn cloud list | grep United | tail -5

avn cloud list | grep United | head -5

avn cloud list | grep United | head -20

NOTE: writes a file (ca_clouds)

avn cloud list | grep -E "California" > ca_clouds && cat ca_clouds

NOTE: writes to a file (not_ca_not_fi_clouds)

avn cloud list | grep -Ev "California|Finland" > not_ca_not_fi_clouds && cat not_ca_not_fi_clouds

avn cloud list | grep -E "California" > ca_clouds && wc -l ca_clouds

regions=('africa' 'australia' 'europe') for r in "${regions[@]}" do avn cloud list | grep $r done

clear && avn cloud list | grep -E 'europe|north america' | grep 'aws-'

avn cloud list | grep -Ev 'CLOUD_DESCRIPTION|=' > clouds_adjusted && wc -l clouds_adjusted

providers=('aws-' 'azure-' 'do-' 'google' 'packet') for p in "${providers[@]}" do avn cloud list | grep $p done

avn service plans --cloud do-sfo

avn service plans --cloud do-sfo | grep -E 'hobbyist'

avn service plans --cloud do-sfo | grep -E 'kafka:'

clear && avn service plans --cloud do-sfo | grep -E 'pg:|kafka:' | grep -E '8 CPU|16 CPU'

avn service plans --cloud do-sfo | grep -E 'cassandra:|elasticsearch:|grafana:|influxdb:|kafka:|mysql:|pg:|redis:' > plans_on_this_cloud && wc -l plans_on_this_cloud

avn service plans --cloud do-sfo | grep -Ev '\$\d\d.\d{3}/h' | grep -E 'cassandra:|elasticsearch:|grafana:|influxdb:|kafka:|mysql:|pg:|redis:' > cheap_plans && wc -l cheap_plans

avn service plans --cloud do-sfo | grep -Ev '\$\d\d.\d{3}/h' > cheap_plans && cat cheap_plans

clear && avn service plans --cloud do-sfo | grep -Ev '\$\d\d.\d{3}/h' | more

clear && avn service plans --cloud do-sfo | grep -E '\$\d\d.\d{3}/h'

avn service create myes -t elasticsearch --plan hobbyist

avn service create mycass -t cassandra --plan startup-4

avn service create mykafka -t kafka --plan business-4

avn service create mycass -t cassandra --plan startup-4 && avn service create mykafka -t kafka --plan business-4

avn service update mycass --plan startup-8

avn service update mycass --plan startup-8 --cloud aws-us-west-1

avn service list

avn service update myes1 --power-on && avn service update myes2 --power-on

avn service list | grep POWERON

avn service list | grep POWEROFF

This command is useful for troubleshooting a slowly-restarting service.

avn service list | grep REBUILDING | grep -Eo '\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(.\d{6})?((\+\d\d:\d\d)|Z)'

avn service list | grep POWEROFF | grep -Eo '\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(.\d{6})?((\+\d\d:\d\d)|Z)'

avn service list | grep RUNNING | grep -Eo '\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(.\d{6})?((\+\d\d:\d\d)|Z)'

avn service update myes --power-off && avn service list

services=('mycass' 'mykafka' 'myes') for s in "${services[@]}" do avn service update $s --power-off done

avn service terminate mycass && avn service terminate mykafka

avn events

avn events | grep -Ev 'TIME|=' | head -5

avn events | grep -E '_maintenance'

avn events | grep -E '_delete'

avn events | grep -Ev 'TIME|=' > events && wc -l events
avn events | grep power > power_events && cat power_events
avn events | grep -Ev power > live_events && cat live_events

avn help
avn -h

avn card -h avn cloud -h avn credits -h avn events -h avn project -h avn service -h avn service create -h

avn card list

avn credits list

avn project list

avn project details

avn vpc list

If you are using a command often, it might be useful to create an alias or a shell function for it. You can add these to .bashrc or to a shell script in your path. Here are some examples:

show_my_clouds() { clear regions=('australia' 'europe' 'north') for r in "${regions[@]}" do avn cloud list | grep $r done }

get_cheap_plans() { clear && avn service plans --cloud do-sfo | grep -Ev '\$\d\d.\d{3}/h' | more }

alias turnon_service='avn service update myes --power-on'

alias turnoff_service='avn service update myes --power-off'

alias get_timestamps='avn service list | grep -Eo "\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(.\d{6})?((\+\d\d:\d\d)|Z)"'

In this piece, we looked at many things you can do with the Aiven command-line interface (CLI) including installation and authentication, viewing clouds, services, regions and plans, working with event logs, getting help, and even creating aliases for frequently-used functions.

We hope that you'll find this not only helpful as a comprehensive primer for Aiven CLI, but also as a general, basic bash reference.

As mentioned before, our CLI is only one of many ways to interact with our globally-available, open source services. Want to try them out? Check out our free 30 day trial. To stay apace with new developments, you can also subscribe to our blog and changelog RSS feeds, or follow us on Twitter or LinkedIn!

Related blogs

All things open source, plus our product updates and news in a monthly newsletter.

Subscribe to the Aiven newsletter

Loading...