关闭 swap 操作

检查:

free -m # 应该 Swap 显示全是 0

备份 /etc/fstab

cp /etc/fstab /tmp/fstab.`date +%F`

删除 /etc/fstab 中 swap 挂载项

vim /etc/fstab

关闭所有 swap

swapoff -a

观察进程使用 swap 和 swapoff -a 之后回收情况,对于不能回收 swap 的进程需要安排时间重启


free -m
for file in /proc/*/status ; do cat $file | awk '/Name|^Pid|VmSwap/{printf $2 " " $3 $4}END{ print ""}' | grep kB | grep -v '0 kB' ; done | sort -k 3 -n

bash countdown

输入 countdown + 秒数,就开始倒计时了

gnu date

function countdown(){  
    local now=$(date +%s)
    local end=$((now + $1))
    while (( now < end )); do   
        printf "%s\r" "$(date -u -d @$((end - now)) +%T)"  
        sleep 0.25  
        now=$(date +%s)
    done  
    echo
}

osx date

function countdown(){  
    echo $2
    local now=$(date +%s)
    local end=$((now + $1))
    while (( now < end )); do   
        printf "%s\r" "$(date -u -j -f %s $((end - now)) +%T)"  
        sleep 0.25  
        now=$(date +%s)
    done
}

参考:https://superuser.com/questions/850368/osx-bash-command-line-countdown-timer?answertab=votes#tab-top

openssl shell 检验 ssl 证书过期时间

语法如下

echo | openssl s_client -servername www.youqiantu.com -connect www.youqiantu.com:443 2>/dev/null | openssl x509 -noout -dates

添加很多域名的 check

#!/bin/bash

domains='
sentry.google.com
console.google.com
www.google.com
m.google.com
api.google.com
'

for domain in $domains
do
  check_result=$(echo | openssl s_client -servername $domain -connect $domain:443 2>/dev/null | openssl x509 -noout -dates | grep After)
  echo "$domain\t $check_result" | awk -F"\t" '{sub(/^ /,"",$2);printf "%-40s%s\n",$1,$2}'
done

对于自己签发的证书

openssl x509 -enddate -noout -in apiserver.pem 
notAfter=Mar  5 13:23:40 2018 GMT