Created
February 8, 2023 08:01
-
-
Save ljyloi/a411fbfc10360b0f2063cf495a6b8d00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# author: @lumean | |
# 用于检测某个 vlan 被哪些进程占用了,将进程的 nents 软连接到 iproute2 配置的 netns 目录下,通过 iproute2 工具查看 netns 中的具体情况 | |
VLAN=$1 | |
mkdir -p /var/run/netns | |
for i in $(ps -e | awk '{print $1}'); do | |
ln -sf /proc/$i/ns/net /var/run/netns/$i | |
output=$(ip -d -n $i addr show) | |
if echo $output | grep -q "1Q id $VLAN"; then | |
echo "vlan $VLAN still in use by PID $i:" | |
echo "$(ps $i)" | |
echo "$output" | |
echo "" | |
fi | |
rm /var/run/netns/$i | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment