常用Shell命令汇总

2024-06-21 549 0

# 获取IP连接所在进程PID
ss -ntep | grep 59.110.246.82

# 获取IP连接所在进程PID 只取PID
ss -ntep | grep 59.110.246.82 | awk -F '=' '{print $2}' | awk -F ',' '{print $1}'

# 获取IP连接所有进程详情
ss -ntep | grep 59.110.246.82 | awk -F '=' '{print $2}' | awk -F ',' '{print $1}' | while read -r pid; do ps -ef | grep -v grep | grep "$pid"; done

# Nginx时间段过滤
sed -n '/11:40:00/,/13:00:00/p' /path/to/nginx/access.log # 不太准
awk '$4 >= "[11/Oct/2024:11:40:00" && $4 <= "[11/Oct/2024:13:00:00"' /path/to/nginx/access.log

# Nginx 时间点切割
awk '{split($4, a, ":"); print a[1]":"a[2]":"a[3]":"a[4]":"a[5]}'

相关文章

发布评论