缘起: docker stop 时往往会比较慢,起原因多半是docker 容器的init进程没有正确处理信号所 …
分类存档:Bash
bash 之变量声明周期
bash 之变量与函数
bash中有个export,可以导出变量给子进程使用; 但是函数没法导出给子进程使用,如下:
tcp server in bash
我想通过nc+bash创建一个tcp server, nc负责收发数据,bash负责处理数据,如何将nc和ba …
bash 之 printf
bash 获取所有pid
1 |
for d in /proc/*;do [[ $d =~ /proc/[0-9]+ ]] && echo ${d#/proc/};done |
ls 可以list /proc …
count words in bash without wc
如何计算字符串中单词的数量,但是不使用wc? eg: [crayon-673d75cca43c53169853 …
cfree ( free in container)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#!/bin/bash CGROUP_DIR=/sys/fs/cgroup/memory UNLIMITTED=9223372036854771712 read mem_total <$CGROUP_DIR/memory.limit_in_bytes read mem_used <$CGROUP_DIR/memory.usage_in_bytes mem_free=$((mem_total - mem_used)) read mem_swap_total <$CGROUP_DIR/memory.memsw.limit_in_bytes read mem_swap_used <$CGROUP_DIR/memory.memsw.usage_in_bytes swap_total=$((mem_swap_total - mem_total)) swap_used=$((mem_swap_used - mem_used)) swap_free=$((swap_total - swap_used)) if [[ $mem_total = "9223372036854771712" ]];then /usr/bin/free -h && exit fi printf "%20s%20s%20s\n" total used free printf "Mem:%16s%20s%20s\n" $((mem_total/1024/1024))M $((mem_used/1024/1024))M $((mem_free/1024/1024))M printf "Swap:%15s%20s%20s\n" $((swap_total/1024/1024))M $((swap_used/1024/1024))M $((swap_free/1024/1024))M |
bash 对单行中的单词进行排序
排序一般使用sort命令,但是,sort命令是基于行的: [crayon-673d75cca46ed50953 …
Shell Style Guide
https://google.github.io/styleguide/shell.xml 建议的bash风格 …