Custom Search

SUBSCRIBE

SUBSCRIBE : 300 + Free Video Tutorials Programming (Python, golang, Julia), DevOps

Wednesday, April 1, 2015

OpenStack find and parse only the ID of all users using CLI and AWK

1)
saju@ubuntu:~$
saju@ubuntu:~$ keystone user-list
+----------------------------------+--------------+---------+---------------------+
|                id                |     name     | enabled |        email        |
+----------------------------------+--------------+---------+---------------------+
| 043e319471b344b38a6a24d487cf4779 |    admin     |   True  |  admin@example.com  |
| c18a866b8bdf459db236e08d15c7da25 |    cinder    |   True  |  cinder@example.com |
| 0cbcb3f31ebe45859dcb454151474196 |     demo     |   True  |   demo@example.com  |
| 2a2c57a8ea6349d1a482de8d5845414d |    glance    |   True  |  glance@example.com |
| ad22bdb11ddd42f59fe688bceba8d648 |     heat     |   True  |   heat@example.com  |
| 93901c78f88d457b9c691acc77380aea |   neutron    |   True  | neutron@example.com |
| 10b6f5dead814142ae7da19c9f9a1f41 |     nova     |   True  |   nova@example.com  |
| fc18cb1bed564edfb95c58d3fcdfb9d6 |   testuser   |   True  |                     |
| e730974265b14001b9f0537eeab186bd |  testuser2   |   True  |                     |
| 03168425d56e4e8fa1b86e252955cbfd |     use3     |   True  |                     |
| d70696f95a7b45309e553a59d0d3949c |    user1     |   True  |                     |
| 094abd49a60b4cfca5152a51c6809b18 | vpc-1ca5e3f6 |   True  |                     |
| fde39ee3fabb4c689a3e5213e80d0f0f | vpc-3e1bdd7b |   True  |                     |
| 97f3af264d834d3d83e23adc3a6f0441 | vpc-4ea2a886 |   True  |                     |
| 1b476671f97b4b7d864b7b67012514be | vpc-6bb138ff |   True  |                     |
| d11ade17c09e47689e16bd9ed077975a | vpc-d737f234 |   True  |                     |
| 83d17e75c4c84777bd0718c176082df4 | vpc-d8e1949c |   True  |                     |
+----------------------------------+--------------+---------+---------------------+
saju@ubuntu:~$
saju@ubuntu:~$



2)
saju@ubuntu:~$ keystone user-list | awk '{print $2}'

id

043e319471b344b38a6a24d487cf4779
c18a866b8bdf459db236e08d15c7da25
0cbcb3f31ebe45859dcb454151474196
2a2c57a8ea6349d1a482de8d5845414d
ad22bdb11ddd42f59fe688bceba8d648
93901c78f88d457b9c691acc77380aea
10b6f5dead814142ae7da19c9f9a1f41
fc18cb1bed564edfb95c58d3fcdfb9d6
e730974265b14001b9f0537eeab186bd
03168425d56e4e8fa1b86e252955cbfd
d70696f95a7b45309e553a59d0d3949c
094abd49a60b4cfca5152a51c6809b18
fde39ee3fabb4c689a3e5213e80d0f0f
97f3af264d834d3d83e23adc3a6f0441
1b476671f97b4b7d864b7b67012514be
d11ade17c09e47689e16bd9ed077975a
83d17e75c4c84777bd0718c176082df4

saju@ubuntu:~$
saju@ubuntu:~$

3)
Remove "id" and space from the output
saju@ubuntu:~$
saju@ubuntu:~$ keystone user-list | awk '{if($2!="id" && $2!="") print $2}'
043e319471b344b38a6a24d487cf4779
c18a866b8bdf459db236e08d15c7da25
0cbcb3f31ebe45859dcb454151474196
2a2c57a8ea6349d1a482de8d5845414d
ad22bdb11ddd42f59fe688bceba8d648
93901c78f88d457b9c691acc77380aea
10b6f5dead814142ae7da19c9f9a1f41
fc18cb1bed564edfb95c58d3fcdfb9d6
e730974265b14001b9f0537eeab186bd
03168425d56e4e8fa1b86e252955cbfd
d70696f95a7b45309e553a59d0d3949c
094abd49a60b4cfca5152a51c6809b18
fde39ee3fabb4c689a3e5213e80d0f0f
97f3af264d834d3d83e23adc3a6f0441
1b476671f97b4b7d864b7b67012514be
d11ade17c09e47689e16bd9ed077975a
83d17e75c4c84777bd0718c176082df4
saju@ubuntu:~$
saju@ubuntu:~$

4)
saju@ubuntu:~$
saju@ubuntu:~$ user_ids=$(keystone user-list | awk '{if($2!="id" && $2!="") print $2}')
saju@ubuntu:~$
saju@ubuntu:~$

5)
saju@ubuntu:~$
saju@ubuntu:~$ for user in $user_ids
> do
> echo $user
> done

043e319471b344b38a6a24d487cf4779
c18a866b8bdf459db236e08d15c7da25
0cbcb3f31ebe45859dcb454151474196
2a2c57a8ea6349d1a482de8d5845414d
ad22bdb11ddd42f59fe688bceba8d648
93901c78f88d457b9c691acc77380aea
10b6f5dead814142ae7da19c9f9a1f41
fc18cb1bed564edfb95c58d3fcdfb9d6
e730974265b14001b9f0537eeab186bd
03168425d56e4e8fa1b86e252955cbfd
d70696f95a7b45309e553a59d0d3949c
094abd49a60b4cfca5152a51c6809b18
fde39ee3fabb4c689a3e5213e80d0f0f
97f3af264d834d3d83e23adc3a6f0441
1b476671f97b4b7d864b7b67012514be
d11ade17c09e47689e16bd9ed077975a
83d17e75c4c84777bd0718c176082df4
saju@ubuntu:~$
saju@ubuntu:~$
saju@ubuntu:~$



No comments:

Post a Comment