-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.sh
executable file
·50 lines (41 loc) · 1.45 KB
/
status.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
red_background="\033[41m" # 红色背景
red="\033[31m" # 红色
green="\033[32m" # 绿色
yellow="\033[33m" # 黄色
blue="\033[34m" # 蓝色
reset="\033[0m" # 重置颜色
echo "[CHECK] OS"
# 使用 uname -s 命令获取系统名称
OS=$(uname -s)
# 检查系统是否为 Darwin(macOS)或 Linux
if [[ "$OS" == "Darwin" ]]; then
printf '%b[STATUS] macOS%b\n' "$yellow" "$reset" >&1
elif [[ "$OS" == "Linux" ]]; then
printf "${yellow}[STATUS] Linux${reset}\n"
fi
# 定义端口数组
ports=(3000 3010 3020)
# 遍历端口数组
for port in "${ports[@]}"; do
echo -e "${blue}[CHECK] port $port: ${reset}"
# lsof -i :$port
# pid=$(lsof -i :$port | awk ' {print $2}')
command=$(lsof -i :$port | awk 'NR==2 {print $1}')
pid=$(lsof -i :$port | awk 'NR==2 {print $2}')
echo -e "${green}[CMD] $command${reset}"
echo -e "${green}[PID] $pid${reset}"
if [[ $OS == "Darwin" ]]; then
# 这里可能有问题 //TODO
app_name=$(ps -ax | grep $pid | awk 'NR==1 {print $4 " " $5}')
echo -e "${green}[APP] app name: $app_name ${reset}"
elif [[ $OS == "Linux" ]]; then
app_name=$(ps -ax | grep $pid | awk 'NR==2 {print $5 " " $6}')
echo -e "${green}[APP] app name: $app_name ${reset}"
# app_name=$(pwdx $pid)
fi
echo "--------------------------"
done
echo "Port check completed."
# lsof -i :3000 | awk '{print $2}'
# lsof -p 59063 -Fn | awk 'NR==2{print}' | sed "s/n\//\//"