CLE Command Live Environment Michael Arbet November 2019 AGENDA - - PowerPoint PPT Presentation

cle
SMART_READER_LITE
LIVE PREVIEW

CLE Command Live Environment Michael Arbet November 2019 AGENDA - - PowerPoint PPT Presentation

CLE Command Live Environment Michael Arbet November 2019 AGENDA Command Line Environment What, Why, for Who What CLE does, What are its purpose and benefjts Living with CLE Installation, confjguration, usage The magic inside Priciples,


slide-1
SLIDE 1

CLE

Command Live Environment

Michael Arbet November 2019

slide-2
SLIDE 2

CLE 11/2018 2

AGENDA

Command Line Environment

What, Why, for Who

What CLE does, What are its purpose and benefjts

Living with CLE

Installation, confjguration, usage

The magic inside

Priciples, variables, tweaks

slide-3
SLIDE 3

CLE 11/2018 3

What, Why & for Who

”Thou shalt have no other shells before bash”

slide-4
SLIDE 4

CLE 11/2018 4

What CLE provides

Colorful prompt!

Distinguish commands and outputs Have important information visible Create your own style

Alias management

Define and remember aliases Edit your alias set

Rich history

More information about your work Endless and easy to search

Live sessions

Seamless login with the same environment without installation No harm to default settings Multi-admin environment

Open framework

Options to add custom features Self documented All in one compact script

slide-5
SLIDE 5

CLE 11/2018 5

Alternatives

  • 1. Your own .bashrc / .zshrc

You know what is there Need to edit the file, relogin Required to be added on each new account

  • 2. 'powerline'

Nice, well known solution Huge complicated python scripts behind Running daemon! (for just cmdline...) Requires installation on destination boxes

  • 3. 'sshrc'

Partially solves seamless transfer Yes this one inspired me!

slide-6
SLIDE 6

CLE 11/2018 6

Who can benefjt from CLE

  • Administrators, accessing a lot of servers *
  • Support engineers creating reproducers
  • Developers
  • ...anybody using command line daily

*) more users access the same root account with individual settings!

Why this all?

  • Install once, use anywhere
  • Easy configuration without reload
  • Lazy admin's live becomes more comfortable
slide-7
SLIDE 7

CLE 11/2018 7

Living with CLE

“Remember the sabbath outage day, to keep it holy”

slide-8
SLIDE 8

CLE 11/2018 8

Start

  • Main source:

http://raw.githubusercontent.com/micharbet/CLE/master/clerc

  • Easy going:

https://git.io/clerc

$ w g e t h t t p : / / g i t . i

  • /

c l e r c $ . c l e r c $ c l e d e p l

  • y

Exercise #1: download & run

slide-9
SLIDE 9

CLE 11/2018 9

First aid kit

CLE employs TAB autocompletion CLE is documented, use following ways to learn more:

  • Quick help (strings inside the script)

c l e h e l p

  • r c

l e

  • h
  • Thorough documentation (download)

c l e d

  • c

You will never walk alone!

slide-10
SLIDE 10

CLE 11/2018 10

Prompting [0] 12:15 fool stalker.usersys ~ $ _

CLE_P1 Username ‘\u’ CLE_P3 Working dierctory ‘\w \$’ CLE_P2 Shortened hostname ‘^h’ CLE_P0 Return code + time ‘^E \A’

Exercise #2: setup prompt colors c l e c

  • l
  • r

c l e c

  • l
  • r

g r e e n c l e c

  • l
  • r

R g B c l e c

  • l
  • r

C g G Y

Use predefined scheme or try your own combinations.

slide-11
SLIDE 11

CLE 11/2018 11

Prompting

Exercise #3: setup your prompt strings c l e t i m e

  • ff

c l e p 1 ' \ u @ ^ h ' c l e p 2 ' $ V A R I A B L E \ n ' c l e p 2 ' ^ c M ^ v V A R I A B L E ' c l e p 2 ' d a t e $ ( d a t e ) ' c l e p 3 ' \ w : ^ g \ $ '

Pro tips:

  • use TAB completion to get current parts definitions
  • find more escape sequences using cle doc

Note: distinguish between bash sequences e.g. ‘\u’ and CLE additions introduced with caret sign e.g. ‘^h’

slide-12
SLIDE 12

INSERT DESIGNATOR, IF NEEDED 12

Live sessions

CLE can pass itself over remote login and su*

Exercise #4: Use lssh instead of ssh

CLE Workstation

s r v 1

[0] fool ws ~ $ lssh root@srv1 (CLE packs itself, transfers through ssh and runs) [0] me-root srv1 ~ # lssh virtual [0] me-root virtual ~ # _

v i r t u a l

slide-13
SLIDE 13

INSERT DESIGNATOR, IF NEEDED 13

Live sessions

CLE can pass itself over remote login and su*

Exercise #5: Use lsu, lsudo or lksu

CLE Workstation

[0] fool ws ~ $ lssh srv1 (CLE packs itself, transfers through ssh and runs) [0] fool srv1 ~ # lksu [0] me-root srv1 ~ # _

r

  • t

@ s r v 1 f

  • l

@ s r v 1

Note: Regular ‘ssh’ and ‘su*’ commands will behave normally, like if CLE does’t exist

slide-14
SLIDE 14

CLE 11/2018 14

CLE in screen

Use command l s c r e e n to start CLE session in GNU screen Features:

  • Customized confjguration
  • Automatic rejoin detached screens
  • Easier screen sharing

Exercise #6: work with l s c r e e n

  • Open more shells <ctrl-A><ctrl-C>
  • Do something (e.g. ‘ls’)
  • Switch windows with <ctrl-Left/Right>
  • Detach screen session <ctrl-A><ctrl-D>
  • Start over, just type ‘l

s c r e e n ’

slide-15
SLIDE 15

CLE 11/2018 15

Work with aliases

a a a a t l g = ' t a i l

  • f

/ v a r / l

  • g

/ m e s s a g e s

Exercise #7: use command aa

Open new session, new aliases are there!

a a a a

  • e

(you can edit your aliases!)

Defjne new alias, watch the alias set

slide-16
SLIDE 16

CLE 11/2018 16

Rich history

2018-08-02 11:02:14 mich-8300 15 2 ~/gam-rh gam add group cpq-development-team 2018-08-02 11:02:30 mich-8300 2 0 ~/gam-rh gam create group cpq-development-team 2018-08-02 11:02:37 mich-8300 2 0 ~/gam-rh gam create group clm-development-team

Timestamp session secs rc dir command

h

(known bash colored history)

h h

(this is the rich history)

h h 1 5

(recent 15 entries)

h h g a m . * g r

  • u

p

(use regexp)

Basic history usage using h h

Did you know shell's < C t r l

  • R

> to interactive search through history?

slide-17
SLIDE 17

CLE 11/2018 17

Rich history

Advanced searches

h h

  • d

g r e p

(all today’s greps)

h h

  • s

h h

  • t

s c

(see only successful commands issued in this terminal)

h h

  • d

s c

(guess the difference)

h h

  • f

5

(folder history within recent 500 commands)

Use ‘cle help hh’ to see all rich history

  • ptions

Exercise #8:

  • inspect rich history over multiple sessions
  • Open live session on the same account and watch history

records of other users

slide-18
SLIDE 18

CLE 11/2018 18

The magic inside

“Thou shalt not steal unless it is open source”

slide-19
SLIDE 19

CLE 11/2018 19

How CLE works

  • Resource file lives in separate folder $

H O M E / . c l e

  • y
  • u

r n a m e

  • Hooked into .

$ { C L E _ S H } r c ( with command c l e d e p l

  • y

)

  • All in one file, including basic documentation
  • Defines bash functions – to be executed in context of current shell

process

  • Seamless live sessions use t

a r and b a s e 6 4 encoding to pass CLE files to remote hosts

  • Self-contained documentation uses '##' double-hash to denote

comments worth to print out using 'c l e h e l p '

slide-20
SLIDE 20

CLE 11/2018 20

Internal variables

Issue 'c l e e n v ' to inspect all variables Use ‘c l e d

  • c

’ and chose file H O W T O . m d to read more

Variable Purpose C L E _ U S E R Username from fjrst login on CLE workstation, inherited

  • ver all live sessions. Most important variable used to

name cle fjles C L E _ R C Full path to the resource fjle itself C L E _ T W Relative path to tweak fjle C L E _ D Directory with working fjles (confjguration and more) C L E _ C F Confjguration fjle C L E _ C L R Color scheme, related command ‘cle color’ C L E _ P x ( x = . . 3 ) Prompt parts defjnitions, related commands ‘cle p1..p3’ _ C x Color table, e.g. $ _ C r contains escape code for red

slide-21
SLIDE 21

CLE 11/2018 21

Files

File/folder Purpose

$ H O M E / . c l e

  • $

C L E _ U S E R Here is almost all that CLE needs. Other mentioned fjles are related to this directory ($CLE_D) … r c Resource fjle with the environment itself ($CLE_RC) … c f Confjguration fjle ($CLE_CF) … t w T weak fjle ($CLE_TW) … a l i a s e s Locally defjned aliases $ H O M E / . h i s t

  • r

y

  • A

L L Rich history fjle $ H O M E / . h i s t

  • r

y

  • $

C L E _ U S E R User’s personal history (replaces .bash_history)

Inspect file H O W T O . m d using ‘c l e d

  • c

’ to read more

slide-22
SLIDE 22

CLE 11/2018 22

T weaks and modules

# t h i s i s m y C L E t w e a k e c h

  • W

e l c

  • m

e $ C L E _ U S E R a s $ U S E R a t $ ( h

  • s

t n a m e

  • f

) # Y e l l

  • w

e r r

  • r

c

  • d

e _ C e = $ _ C Y

Using ‘c l e d

  • c

’ inspect following files: TipsAndTweaks.md Modularity.md

  • Try not to edit CLE resource file itself. Instead submit bugs or feature

requests on Github

  • Place following code into your $

H O M E / . c l e

  • $

C L E _ U S E R / t w :

Make it yours!

Use ‘c l e m

  • d

’ to enhance functionality, e.g.: c l e m

  • d

a d d p r

  • m

p t c l e p r

  • m

p t t r i l i n e r # t h i s i s m y C L E t w e a k e c h

  • W

e l c

  • m

e $ C L E _ U S E R a s $ U S E R a t $ ( h

  • s

t n a m e

  • f

) # Y e l l

  • w

e r r

  • r

c

  • d

e _ C e = $ _ C Y

slide-23
SLIDE 23

CLE 11/2018 23

Go deeper, have fun

  • Check how things are coded
  • Close look at use of variable $

C L E _ U S E R – how it is created then inherited over sessions and how it ensures multi-admin environment.

  • See comments, esp. Self-documentation
  • Note, it might be sometimes not easy to read, code is quite dense,

heavily using regular expressions, etc...

Exercise #9: find Easter Egg!

  • It's there!
  • Uses function '

c l e '

Review the script!

slide-24
SLIDE 24

Thank you!

“Make love, not core dumps!” The creator: micharbet@gmail.com The project: https://github.com/micharbet/CLE