sh 观看Journalctl

watch_journalctl
sudo journalctl -f -u someservice.service

sh 创建kafka和zookeeper docker

kafka_docker

docker network create kafka
docker run -d --name zookeeper --network kafka -p 2181:2181 wurstmeister/zookeeper
docker run -d --name kafka -p 9092:9092 --network kafka --env KAFKA_ADVERTISED_HOST_NAME=172.17.0.1 --env KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 wurstmeister/kafka

sh bash别名

aliases.sh
## get rid of command not found ##
alias cd..='cd ..'
 
## a quick way to get out of current directory ##
alias ..='cd ..'
alias ...='cd ../../../'
alias ....='cd ../../../../'
alias .....='cd ../../../../'
alias .4='cd ../../../../'
alias .5='cd ../../../../..'

## Colorize the grep command output for ease of use (good for log files)##
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'

## Calc
alias bc='bc -l'

## SHA1 digest
alias sha1='openssl sha1'

## Create parent if missing
alias mkdir='mkdir -pv'

## diff -> colordiff (req. colordiff)
alias diff='colordiff'

## User-friendly mount output
alias mount='mount |column -t'

## handy short cuts #
alias h='history'
alias j='jobs -l'

alias path='echo -e ${PATH//:/\\n}'
alias now='date +"%T"'
alias nowtime=now
alias nowdate='date +"%d-%m-%Y"'

## Stop after sending count ECHO_REQUEST packets #
alias ping='ping -c 5'
## Do not wait interval 1 second, go fast #
alias fastping='ping -c 100 -s.2'

## Show open ports
alias ports='netstat -tulanp'

## become root 
alias root='sudo -i'
alias su='sudo -i'

## reboot / halt / poweroff
alias reboot='sudo /sbin/reboot'
alias poweroff='sudo /sbin/poweroff'
alias halt='sudo /sbin/halt'
alias shutdown='sudo /sbin/shutdown'

## pass options to free ##
alias meminfo='free -m -l -t'
 
## get top process eating memory
alias psmem='ps auxf | sort -nr -k 4'
alias psmem10='ps auxf | sort -nr -k 4 | head -10'
 
## get top process eating cpu ##
alias pscpu='ps auxf | sort -nr -k 3'
alias pscpu10='ps auxf | sort -nr -k 3 | head -10'
 
## Get server cpu info ##
alias cpuinfo='lscpu'
 
## older system use /proc/cpuinfo ##
##alias cpuinfo='less /proc/cpuinfo' ##
 
## get GPU ram on desktop / laptop##
alias gpumeminfo='grep -i --color memory /var/log/Xorg.0.log'

## this one saved by butt so many times ##
alias wget='wget -c'

## set some other defaults ##
alias df='df -H'
alias du='du -ch'
 
# top is atop, just like vi is vim
alias top='atop'
 
## nfsrestart  - must be root  ##
## refresh nfs mount / cache etc for Apache ##
alias nfsrestart='sync && sleep 2 && /etc/init.d/httpd stop && umount netapp2:/exports/http && sleep 2 && mount -o rw,sync,rsize=32768,wsize=32768,intr,hard,proto=tcp,fsc natapp2:/exports /http/var/www/html &&  /etc/init.d/httpd start'
 
## Memcached server status  ##
alias mcdstats='/usr/bin/memcached-tool 10.10.27.11:11211 stats'
alias mcdshow='/usr/bin/memcached-tool 10.10.27.11:11211 display'
 
## quickly flush out memcached server ##
alias flushmcd='echo "flush_all" | nc 10.10.27.11 11211'
 
## Remove assets quickly from Akamai / Amazon cdn ##
alias cdndel='/home/scripts/admin/cdn/purge_cdn_cache --profile akamai'
alias amzcdndel='/home/scripts/admin/cdn/purge_cdn_cache --profile amazon'
 
## supply list of urls via file or stdin
alias cdnmdel='/home/scripts/admin/cdn/purge_cdn_cache --profile akamai --stdin'
alias amzcdnmdel='/home/scripts/admin/cdn/purge_cdn_cache --profile amazon --stdin'

# if user is not root, pass all commands via sudo #
if [ $UID -ne 0 ]; then
    alias reboot='sudo reboot'
    alias update='sudo apt-get upgrade'
fi

## List files in order of ascending size (the second form takes a file-pattern argument):
function lsdu() { ls -l $* | sort --key=5.1 -n; };
function lsduf() { ls -l | egrep $* | sort --key=5.1 -n; };

## List the 10 most recently edited/changed files (m = more, a poor-man’s more)
alias lsm='ls -lt | head -n 10'

## List the tasks using the most CPU time
alias hogs='ps uxga | sort --key=4.1 -n'

## Count the number of files in current dir
alias lsc='ls -l | wc -l'
 
## Sort directories by sizes
alias dush='du -h --max-depth=1 | sort -h'
 
## Can't see all the files in one page ?
alias lsless='ls | less'
 
## Make a video capture of the desktop
alias capturedesktop='avconv -f x11grab -r 25 -s 1900x1000 -i :0.0+0,24 -vcodec libx264  -threads 0'
 
## Capture desktop, with sound
alias capturedesktop_withsound='avconv -f x11grab -r 25 -s 1900x1000 -i :0.0+0,24 -vcodec libx264  -threads 0 -f alsa -i hw:0 '
 
## Only print actual code/configuration
alias removeblanks="egrep -v '(^[[:space:]]*#|^$|^[[:space:]]*//)'"
 
## Useful when you want to scp to your own machine from a remote server
alias myip='ifdata -pa eth1'

## Readable memory info
alias minfo='egrep "Mem|Cache|Swap" /proc/meminfo'

sh 找到* .so加载了pyinstaller

inspect-pyinstaller-app.sh
cmd="$1"

dir=$(dirname $(realpath $cmd))

$cmd &

pyinstaller_ppid="$!"

#echo $pyinstaller_ppid
#ps -o pid,ppid
#ps uf

sleep 0.3

ps -o pid,ppid | awk -v ppid=$pyinstaller_ppid '
$2 == ppid {
    print $1
}
' | xargs lsof -p | awk '{print $9}' | grep '\.so' | grep $dir

kill $pyinstaller_ppid
pyinstaller-app-lite.sh
cmd=$(realpath "$1")

dir=$(dirname $cmd)

$cmd &

pyinstaller_ppid="$!"

#echo $pyinstaller_ppid
#ps -o pid,ppid
#ps uf

sleep 0.3

mkdir -p tmp
mkdir -p pre

ps -o pid,ppid | awk -v ppid=$pyinstaller_ppid '
$2 == ppid {
    print $1
}
' | xargs lsof -p | awk '{print $9}' | grep '\.so' | grep $dir | xargs -I X cp X tmp


kill $pyinstaller_ppid
#exit

mv $dir/*.so* pre
mv tmp/* $dir

sh Ledger Blue / NanoS / NanoX环境设置

Ledger Blue / NanoS / NanoX环境设置

prepare-devenv.sh
## Install Development Environment

There are two options for setting up our environment

**Option 1**: Using Ledger Vagrant
-   Clone ledger-vagrant  
    > `git clone https://github.com/fix/ledger-vagrant`
-   Connect to the vagrant machine  
    > `vagrant ssh`
-   Move to the app  
    > `cd apps/ark-ledger`


**Option 2**: Using Python3-env.

Linux:  
-   > `sudo apt install python3-venv`

macOS:
-   > `brew install python3`
-   > `pip3 install virtualenv`

Now we prepare the Ledger device environment.
-   > `source prepare-devenv.sh x`
    > _(x or s, depending on your device)_  

> *_note: `deactivate` to exit python3-env

## Building and flashing our app
-   Connect your ledger Nano S
-   Run the script
    > `sh ./rebuild.sh` (ie. build, delete and load app on ledger)



# shellcheck disable=SC1091,SC2155

# SOURCE THIS FILE
# . prepare-devenv blue|s|x


# To prepare your dev environment
#
# sudo apt install python3-venv
#
# source prepare-devenv.sh x 
# (x or s, depending on your device)

# To build/rebuild
# sh ./rebuild.sh

# If this process gets stuck or bugs out,
# just delete the 'dev-env' folder and run this script again.

# If you get `hidapi` errors, install the following:
# apt-get install libudev-dev libusb-1.0-0-dev -y > /dev/null

if [ $# -ne 1 ]; then
    echo "Possible options: blue, s or x"
    return
elif [[ $1 == "-h" ]]; then
    echo "Possible options: blue, s or x"
    return
elif [[ $1 != "blue" ]] && [[ $1 != "s" ]] && [[ $1 != "x" ]]; then
    echo "Possible options: blue, s or x"
    return
fi

if [[ $(dpkg-query -s python3-venv 2>&1) == *'is not installed'* ]]; then
    printf "\nPackage python3-venv is missing.\nOn Debian-like distros, run:\n\napt install python3-venv\n\n"
    return
fi

if [[ $(cat /etc/udev/rules.d/20-hw1.rules) == *'ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="0004"'* ]]; then
    printf "\nMissing udev rules. Please refer to https://support.ledger.com/hc/en-us/articles/115005165269-Fix-connection-issues\n\n"
    return
fi

if [ ! -d dev-env ]; then
    mkdir dev-env
    mkdir dev-env/SDK
    mkdir dev-env/CC
    mkdir dev-env/CC/others
    mkdir dev-env/CC/nanox

    mkdir temp
    wget -q https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q1-update/+download/gcc-arm-none-eabi-5_3-2016q1-20160330-linux.tar.bz2 -O temp/gcc-arm-none-eabi-5_3-2016q1-20160330-linux.tar.bz2 --show-progress
    tar xjf temp/gcc-arm-none-eabi-5_3-2016q1-20160330-linux.tar.bz2 --directory temp/
    ln -s /opt/bolos/gcc-arm-none-eabi-5_3-2016q1/bin/arm-none-eabi-gcc /usr/bin/arm-none-eabi-gcc

    wget http://releases.llvm.org/4.0.0/clang+llvm-4.0.0-x86_64-linux-gnu-ubuntu-16.10.tar.xz -O temp/clang+llvm.4.tar.xz --show-progress
    tar xf temp/clang+llvm.4.tar.xz --directory temp/clang+llvm.4
    rm temp/clang+llvm.tar.xz
    mv temp/clang+llvm.4* dev-env/CC/others/clang-arm-fropi

    # wget http://releases.llvm.org/7.0.0/clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz -O temp/clang+llvm.tar.xz
    wget -q https://releases.llvm.org/8.0.0/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz -O temp/clang+llvm.8.tar.xz --show-progress
    tar xf temp/clang+llvm.8.tar.xz --directory temp/
    rm temp/clang+llvm.tar.xz
    mv temp/clang+llvm* dev-env/CC/nanox/clang-arm-fropi

    wget https://github.com/LedgerHQ/blue-secure-sdk/archive/blue-r21.1.tar.gz -O temp/blue-secure-sdk.tar.gz --show-progress
    tar xf temp/blue-secure-sdk.tar.gz --directory temp/
    rm temp/blue-secure-sdk.tar.gz temp/
    mv temp/blue-secure-sdk* dev-env/SDK/blue-secure-sdk

    wget https://github.com/LedgerHQ/nanos-secure-sdk/archive/nanos-1553.tar.gz -O temp/nanos-secure-sdk.tar.gz --show-progress
    tar xf temp/nanos-secure-sdk.tar.gz --directory temp/
    rm temp/nanos-secure-sdk.tar.gz
    mv temp/nanos-secure-sdk* dev-env/SDK/nanos-secure-sdk

    python3 -m venv dev-env/ledger_py3
    source dev-env/ledger_py3/bin/activate
    pip install wheel
    pip install ledgerblue
fi


source dev-env/ledger_py3/bin/activate

if [[ $1 == "blue" ]]; then
    export BOLOS_SDK=$(pwd)/dev-env/SDK/blue-secure-sdk
    export BOLOS_ENV=$(pwd)/dev-env/CC/others
elif [[ $1 == "s" ]]; then
    export BOLOS_SDK=$(pwd)/dev-env/SDK/nanos-secure-sdk
    export BOLOS_ENV=$(pwd)/dev-env/CC/others
elif [[ $1 == "x" ]]; then
    export BOLOS_SDK=$(pwd)/dev-env/SDK/nanox-secure-sdk
    export BOLOS_ENV=$(pwd)/dev-env/CC/nanox
fi

sh Crontab禁止重叠

crontab.sh
*/5 * * * * flock -n /tmp/foo_lock -c "echo 'Foo'"

sh linux开始时间

uptime

last reboot

date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M:%S"

sh 在Bash中写多行注释

在外壳中撰写多行注释

write_multiline_comments_in_bash
<<COMMENT
...
COMMENT

sh 从命令行列出OS X的用户帐户

列出的MacBook中所有用户

list_user_accounts_of_os_x_from_command_line
# view all users and accounts of OS X
dscl . list /Users

# show user accounts only
dscl . list /Users | grep -v '_'

sh 在macbook上找到PostgreSQL目录

在的MacBook中找到postgres的的安装目录,可以用终端命令行的管道命令,也可以用SQL语句

find_postgresql_directory_on_macbook
# if you have a postgres server running on your macbook, you can find the config directory using the following command
# the "-D" option in the result show the directory of the PostgreSQL
ps aux | grep postgres

# or, if you can connect to your PostgreSQL server via psql, then use the following command
SHOW data_directory;