06 June 2018

inotify

while true; do
    inotifywait --exclude XXX -rqe modify /path/to/dir_or_file;
    do_something
    sleep 3   # 决定 sleep 多久重新监听 inotify(这里不 sleep 会有问题问题,比如一个目录同时更新了 3 个文件,那个 `do_something` 就会被执行 3 次)
done

lsof

lsof -i tcp:9999

redis del by pattern

# 密码有 "!" 要先转义 "\!"
redis-cli -h 127.0.0.1 -a "xxxx#\!xxx#%*" keys * | xargs redis-cli -h 127.0.0.1 -a "xxxx#\!xxx#%*" del

ps kill

ps -aux | grep NAME | awk '{print $2}' | xargs kill

ps kill remote

# "$2" 要先转义成 "\$2"
ansible all -i /path/to/ip_file -m shell -a "ps -aux | grep inotify | awk '{print \$2}' | xargs kill"