2019年9月23日 星期一

阿班 Bash 常用指令範例




 sed

刪除空白行

語法

/^$/d

範例

bash-5.0# echo -e "te\n\nst" | sed "/^$/d"
te
st


xargs

語法

xargs [argument1] [argument2] ...

範例

bash-5.0# find . -type f | xargs wc -l | sed -e "s/^[ \t]*//g"
2 ./b.txt
1 ./c.txt
3 ./a.txt
6 total

2019年9月16日 星期一

阿班 Docker 指令備忘範例

啟動 Docker Container


自動啟動 Container

 編修日期: 2019-9-23

使用情境

docker machine 重啟後,依設定規則來自動執行對應的 Docker Containers

參考文件

https://docs.docker.com/config/containers/start-containers-automatically/

語法

docker update --restart always container-id [...]

or
docker update --restart always container-name [...]

範例

docker update --restart always my-testapp my-testapp2

2019年6月29日 星期六

Bash Tip - Why .bashrc (dot bashrc) not loaded after new user created?


Recently, I reinstalled ubuntu 16.04LTS on my desktop as a Linux server.

After a new user created, ssh into the server each time, but .bashrc (dot bashrc) not loaded after new user created? Please try to modify the profile as bellow.

Append some commands into ~/.profile

result of test-cases.sh example

~$ source .profile
load /home/ben/.bashrc by ~/.profile
.bashrc has been executed once

Appendix


2019年5月13日 星期一

開源 RISC OS Pi 系統 - 初探





1987 開始發展的RISC OS, 終於在2018年10月以Apache 2.0 License 開源,允許商業使用。

近來忙裡偷閒,用樹梅派最新版本 Raspberry Pi 3 Model B+ 安裝了RISC OS PI ,號稱是ARM 架構下快速也易於客制化的作業系統 (A fast and easily customized operating system for ARM devices)。

初步試用, 它的視窗環境用起來執行程式反應很快(相比Raspbian  based X-Window 來說)。

並試了一些常用工具都有替代的APP可以使用
Ex:
  • Nettle(ssh/telnet client)
  • LanMan (Samba client)
  • NetSurf (Browser) ...


不過還需要更多開源高手投入時間進一步改善。

安裝方式是以NOOBS來安裝 RISC OS PI




小結

待機耗電量約在 2.93W (4.89V, 0.6A)運行較吃CPU資源大約升高到 3.9W (4.89V, 0.8A),以一個迷你作業系統而言,還算省電。有興趣的朋友可以裝起來試玩看看。






參考資料


延伸閱讀

2019年5月9日 星期四

DevOps Tip - Got error - not found aws-iam-authenticator for kubectl using?


Problem

I've got error to run kubectl command with aws-iam-authenticator not found

(venv) ➜  k8s git:(develop) ✗ kubectl get pod
Unable to connect to the server: getting credentials: exec: exec: "aws-iam-authenticator": executable file not found in $PATH


Solutions

Installation tool on OSX Mojave

brew install aws-iam-authenticator

Example of installation

 (venv) ➜  k8s git:(develop) ✗ brew install aws-iam-authenticator
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 3 taps (homebrew/core, homebrew/cask and caskroom/cask).
==> New Formulae
..
==> Downloading https://homebrew.bintray.com/bottles/
aws-iam-authenticator-0.4.0.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/52...
######################################################################## 100.0%
==> Pouring aws-iam-authenticator-0.4.0.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/aws-iam-authenticator/0.4.0: 5 files, 31.1MB

References


2019年4月11日 星期四

Python Tip - Examples of initialize variables with sequence number in different ways

Purpose

It is used to collect sample code for python's coding tips of initialization variables.

A. Variables with constants

test_init_vars.py

#!/usr/bin/env python

a=0
b=1
c=2
d=3
e=4
f=5
print(a, b, c, d, e, f)

B. Use range()

test_init_vars_by_range.py

#!/usr/bin/env python

a, b, c, d, e, f = range(6)

print(a, b, c, d, e, f)

C. Use enum since python 3.4 supported

test_init_vars_by_enum.py

#!/usr/bin/env python3.6

from enum import IntEnum,auto

class Vars(IntEnum):
    a=0
    b=auto()
    c=auto()
    d=auto()
    e=auto()
    f=auto()

print("{}, {}, {}, {}, {}, {}".format(Vars.a, Vars.b, Vars.c, Vars.d, Vars.e, Vars.f))

Result

$ python2.7 test_init_vars.py
(0, 1, 2, 3, 4, 5)
$ python3.6 test_init_vars.py
0 1 2 3 4 5

$ python2.7 test_init_vars_by_range.py
(0, 1, 2, 3, 4, 5)
$ python3.6 test_init_vars_by_range.py
0 1 2 3 4 5

$ python2.7 test_init_vars_by_enum.py
Traceback (most recent call last):
  File "test_init_vars_by_enum.py", line 3, in
    from enum import IntEnum,auto
ImportError: cannot import name auto

$ python3.6 test_init_vars_by_enum.py
0, 1, 2, 3, 4, 5

References